HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: strange error in shell script
Operating System - HP-UX
1833341
Members
3865
Online
110051
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 08:24 PM
03-31-2005 08:24 PM
strange error in shell script
We got strange shell behavior in one script. Tested on Linux/AIX/Unixware - everything Ok, only HP-UX failes (script hangs forever).
We pass output of some command ("ls" of directory, which contains 1000 files or "cat" etc.) to "while read ..." loop. Inside the loop we run some commands in background and wait for completion of these commands, but "wait" lasts forever (because "ls" command acts as a "job" and "wait" command waits for it.
System: rp8400, HP-UX 11.11, sh/ksh
Testcase:
##################
i=0
while true
do
echo $i > newfile${i}.txt
i=`expr $i + 1`
if [ $i -eq 1000 ]; then
break
fi
done
echo "Done create files..."
FILES_LIST=fileslist.lst
if [ -f $FILES_LIST ]; then
rm -f $FILES_LIST
fi
echo "Total files count "`ls -1 | wc -l`
ls -1 | while read FILENAME
do
jobs
echo $FILENAME >> $FILES_LIST &
jobs
echo $FILENAME
wait
done
##################
Has anybody an explanation? We have workaround, but we'd like to understand the cause of this trouble!
We pass output of some command ("ls" of directory, which contains 1000 files or "cat" etc.) to "while read ..." loop. Inside the loop we run some commands in background and wait for completion of these commands, but "wait" lasts forever (because "ls" command acts as a "job" and "wait" command waits for it.
System: rp8400, HP-UX 11.11, sh/ksh
Testcase:
##################
i=0
while true
do
echo $i > newfile${i}.txt
i=`expr $i + 1`
if [ $i -eq 1000 ]; then
break
fi
done
echo "Done create files..."
FILES_LIST=fileslist.lst
if [ -f $FILES_LIST ]; then
rm -f $FILES_LIST
fi
echo "Total files count "`ls -1 | wc -l`
ls -1 | while read FILENAME
do
jobs
echo $FILENAME >> $FILES_LIST &
jobs
echo $FILENAME
wait
done
##################
Has anybody an explanation? We have workaround, but we'd like to understand the cause of this trouble!
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 09:14 PM
03-31-2005 09:14 PM
Re: strange error in shell script
Igor,
could it be that not the ls but the | acts as a job?
If you shorten for ls loop to:
ls -1 *.txt | while read FILENAME
do
jobs
wait
done
You will see that a job[1] is running, which I believe could be the pipe.
Regards
could it be that not the ls but the | acts as a job?
If you shorten for ls loop to:
ls -1 *.txt | while read FILENAME
do
jobs
wait
done
You will see that a job[1] is running, which I believe could be the pipe.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 11:51 PM
03-31-2005 11:51 PM
Re: strange error in shell script
I agree with Peter.
Read the following paragraph extracted from ksh manual pages:
A pipeline is a sequence of one or more commands separated by |. The standard output of each command except the last is connected by a pipe (see pipe(2)) to the standard input of the next command. Each command is run as a separate process; the shell waits for the last command to terminate. The exit status of a pipeline is the exit status of the last command in the pipeline.
Read the following paragraph extracted from ksh manual pages:
A pipeline is a sequence of one or more commands separated by |. The standard output of each command except the last is connected by a pipe (see pipe(2)) to the standard input of the next command. Each command is run as a separate process; the shell waits for the last command to terminate. The exit status of a pipeline is the exit status of the last command in the pipeline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 01:25 AM
04-01-2005 01:25 AM
Re: strange error in shell script
Thanks, people!
We should use () to avoid such situation, for example instead of
ls -1|while read f;do jobs;echo $f;done
we should use
ls -1|(while read f;do jobs;echo $f;done)
We should use () to avoid such situation, for example instead of
ls -1|while read f;do jobs;echo $f;done
we should use
ls -1|(while read f;do jobs;echo $f;done)
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP