- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sh-posix and ksh feature or bug?
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
10-18-2002 03:18 AM
10-18-2002 03:18 AM
Sometimes the function returns 0 (as expected) and sometimes it returns 129. Problem seems to be, that the execution of the "echo $? >$tmpfile" command is perfomed (sometimes) after the $tempfile is read after the pipe command.
My understanding of the execution of the pipe command was, that all processes of the pipe have to be finished, before the next statement is stating execution. Am I wrong with this assumption, or is there a bug in the implementation of ksh and sh-posix. The problem did not show with the old Bourne shell or with bash.
#! /usr/bin/sh
# write to logfile and also to stderr, return exit code of command
logandshow()
{
set -x
tmpfile="$(mktemp -c -p ers)"
logfile="$1"
shift
{ "$@"; echo "$?">$tmpfile; } | tee -a "$logfile"
RC=`cat "$tmpfile"`
RC=${RC:-129}
set +x
return $RC
}
logandshow "shelltest.logfile" sleep 1
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 05:03 AM
10-18-2002 05:03 AM
Re: sh-posix and ksh feature or bug?
change this line
{ "$@"; echo "$?">$tmpfile; } | tee -a "$logfile"
to this
{ "$@"; echo "$?">$tmpfile; } | tee -a "$logfile";sleep 1
That way you force the "tee" to COMPLETE before proceeding to next line
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 05:13 AM
10-18-2002 05:13 AM
Re: sh-posix and ksh feature or bug?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 05:25 AM
10-18-2002 05:25 AM
Re: sh-posix and ksh feature or bug?
I think its related to the buffering of output.
This works:
{ "$@"; echo "$?">$tmpfile | tee -a "$logfile"; }
by moving the "tee" and attaching it to the "echo" statement.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 05:28 AM
10-18-2002 05:28 AM
SolutionIt's of course a race, but we don't believe that's a shell bug...
The left side of the pipe (the echo command) redirects stdout (from where the pipe is reading) to a file. In this case the pipe may complete before the echo is finished.
This works:
{ "$@"; echo "$?">$tmpfile; true; } | tee -a "$logfile"
Regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 08:29 AM
10-18-2002 08:29 AM
Re: sh-posix and ksh feature or bug?
So I introduced a wait after the pipeline, which worked as well.
In the meanwhile I found a statement in the man pages of sh-posix.
"If the pipeline is not in the background, the shell will wait for the last command specified in the pipeline to complete, and may also wait for all commands to complete."
I think, that clarifies the the HPUX implementations are within specs. Although it would be a nice feature, if the shells waited for all commands to complete.