Bash shell $PIPESTATUS
Re: pipes and return code
This Linux newgroup post called my attention to a Bash feature I
had never noticed: PIPESTATUS. It's an array that holds the exit
status of your last foreground pipeline commands.
For example (this is Bash shell)
ls | wc -k
Will give you a 1 because "wc -k" fails.
It's sometimes useful to grab the whole thing:
ls | wc -k | foo
will give you "0 1 127" - unless you have a "foo" command on
your system. "ls" is 0, "wc -k" is 1, and the non-existent foo
causes the "127".
PIPESTATUS was broken on some earlier Bash shells,
This is obviously useful in scripts that need to be sure of
Got something to add? Send me email.
Increase ad revenue 50-250% with Ezoic
More Articles by Tony Lawrence
Find me on Google+
© 2011-04-04 Tony Lawrence