Christof Warlich
2018-10-28 09:39:05 UTC
Hi,
I'm a bit surprised w.r.t. the implemented (and documented) behavior of
-o pipefail:
Why is the last instead of the first error code in a pipe returned? Example:
$ bash -o pipefail -c '(exit 42) | (exit 43) | (exit 0)'; echo $?
43
IMHO, returning the first error code (i.e. 42 in the previous example)
would be much more intuitive and useful, as errors in subsequent
pipeline steps are most likely just only due to errors in previous
steps. But maybe I'm missing an important point and there is (and / or
was) a good reason that matters are as they are?
Cheers,
Chris
P.S.: I know that the ${PIPESTATUS[@]}-array allows compehensive access
to all exit codes of a pipe, so admittedly, my question may only be
considered as a matter of aesthetics.
I'm a bit surprised w.r.t. the implemented (and documented) behavior of
-o pipefail:
Why is the last instead of the first error code in a pipe returned? Example:
$ bash -o pipefail -c '(exit 42) | (exit 43) | (exit 0)'; echo $?
43
IMHO, returning the first error code (i.e. 42 in the previous example)
would be much more intuitive and useful, as errors in subsequent
pipeline steps are most likely just only due to errors in previous
steps. But maybe I'm missing an important point and there is (and / or
was) a good reason that matters are as they are?
Cheers,
Chris
P.S.: I know that the ${PIPESTATUS[@]}-array allows compehensive access
to all exit codes of a pipe, so admittedly, my question may only be
considered as a matter of aesthetics.