ash - exit code for a piped process
loic.grenie at gmail.com
Sat Aug 4 06:45:56 PDT 2007
2007/8/4, Alexander Kriegisch <Alexander at kriegisch.name>:
> I would like to determine the exit code of 'foo' in
> foo | bar
> I bash there is the PIPESTATUS array, but in ash (which I must use)
> there is no such thing as PIPESTATUS or arrays. Is there any canonical
> way or at least a workaround to achieve both piping the foo's output
> into bar unconditionally *and* determining foo's exit code?
x=`((( foo 3>&- 4>&- ); echo $? >&3)| bar >&4 3>&- 4>&-) 3>&1` 4>&1
should do the trick. The exit code of foo is in x, the output of bar
goes to the output of the command.
Hope this helps.
More information about the busybox