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!
Comments:

Post a Comment:
Comments are closed for this entry.
About

petesh

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today