The exit code of a pipe is the result of the last executed command...
How do I know if any of the other commands originated an exit code different
from 0?
Some examples (with Perl
perl -e 'exit 3' | perl -e 'exit 2'exit code => 2
perl -e 'exit 3' | perl -ne 'exit 2'exit code => 3
perl -e 'exit 3' | perl -e 'exit 0'exit code => 0How can I get that 3 on the first and last examples?
Errors from shell pipes are painful (Score:1)
perl -e 'exit 1';rc1=$? | perl -e 'exit 0'; rc2=$? echo $rc1Correction... (Score:1)
Re:Errors from shell pipes are painful (Score:1)
However, it seems parens are needed, no? Something like:
(perl -e 'exit 1';rc1=$?) | perl -e 'exit 0';rc2=$?Because otherwise the second command on the pipe will only get the result of the atribution to rc1 ;-)
But that works :-)
Thanks a lot for the idea :-)
Re:Errors from shell pipes are painful (Score:1)
Re:Errors from shell pipes are painful (Score:2)
(You can echo those status assignments to stderr or stdout and catch