How do I test the exit code for individual commands tied together by pipe?
2007-12-24 20:33:00
How do I test the exit code of individual commands linked by pipe?
PROGRAM:
Unix Bourne shell
THE PROBLEM:
I am programming an init.d script in sh and need to test exit status of the
command "startud" that is in the below pipe.
$UDTBIN/startud | tee -a $LogFile 2>&1
Stat=$?
if [ $Stat -eq 0 ];then
if
The above does not work for me as "$Stat" == the exit code for "tee" not
"startud". How do I get the exit status for "startud" from the above pipe
without breaking the pipe (I need all output to goto both the crt and a
file)?
THE STORY:
A long time ago, in an office far far away...
"SHELL WARS"
In years gone by, back during the 'shell wars' (before the 'clone wars'), I
fought as a "c sheller" (a Jedi) against "sh" (the dark side). I have a
recollection that during one combat with a sh sheller (a very vicious Sith
Lord named Neki), I remember being surprised by his statement and code to
backup how "sh" could individual test the exit code of multiple commands
tied together with pipes. That night I could offer no reply for "csh" and
"sh" won that battle. I Also remember, that some time later, I reading a
very good "flame mail" (again in the old days when "flame mail" was good and
made you think and laugh) that said same and gave code sample.
Today I needed to write a /etc/init.d script in "sh" and do exactly what
those "sh shellers" were doing then but I do not remember the syntax (aaak!!
I have been seduced by the dark side,,, HELP!!!).
All input is welcomed.
Please advise...
Thx, Bye,
Chris O'Neal
email: onealwc at agedwards.com
DATE: 08-13-2001
***************************************************************************************
WARNING: All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
***************************************************************************************
Comments
Got something to say?
You must be logged in to post a comment.

