Wednesday January 26, 2005
Exit status from commands in a pipeline (ksh)
It's already answered in the comp.unix.shell FAQ, so stop asking me!
For the most part it's the slightly more compatible shells that require some work. As the ksh that ships in Solaris needs to be compatible with practically everything it's a bit tough to insist that people convert their scripts to languages that may not be present on all their machines.
The one I learned (moons ago) was to execute each of the elements in the background, and then wait on the exit status of each of the processes one by one.
mkfifo /tmp/fifo1
tar cf /tmp/fifo1 /blob&
pid1=$!
gzip -c /tmp/fifo1 >compressed.tar.gz&
pid2=$!
wait $pid1
tarstatus=$?
if (( tarstatus != 0 )); then
echo "tar command exited with: $tarstatus"
fi
wait $pid2
gzipstatus=$?
if (( gzipstatus != 0 )); then
echo "gzip command exited with: $gzipstatus"
fi
I'm never using this ever again!
January 26, 2005 05:02 PM GMT
Permalink