[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] behavior of -o pipefail
From: |
Christof Warlich |
Subject: |
Re: [Help-bash] behavior of -o pipefail |
Date: |
Mon, 29 Oct 2018 08:14:26 +0100 |
> Because that's how Bourne-style shells have always behaved,
But the standard (Bourne) shell doesn't even seem to support -o
pipefail:
$ sh -o pipefail -c '(exit 42) | (exit 43) | (exit 0)'; echo $?
sh: 0: Illegal option -o pipefail
2
And ksh seems to ignore it:
ksh -o pipefail -c '(exit 42) | (exit 43) | (exit 0)'; echo $?
0
And zsh seems to have implemented it recent versions only.
Could you give examples of other Borne-style shells that _do_ support
-o pipefail?
> Posix standardizes it
I could not find that. Instead,
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.htm
l#tag_02_09_02
only says:
Exit Status
If the reserved word ! does not precede the pipeline, the exit status
shall be the exit status of the last command specified in the pipeline.
Otherwise, the exit status shall be the logical NOT of the exit status
of the last command. That is, if the last command returns zero, the
exit status shall be 1; if the last command returns greater than zero,
the exit status shall be zero.
Furthermore,
https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html
gave me the impression that bash's standard (i.e. non-Posix) mode may
deviate from POSIX when it suggests something that (as in this case)
may certainly be regarded as bad practice.
> and there are millions of scripts that depend on it.
Scripts that use -o pipefail certainly do depend on getting an error
code when any of the pipeline steps fail, but I really doubt that any
script depends on getting the error code of the _last_ failing command
if a _previous_ pipeline step failed alredy. As I pointed out in my
initial post, returning the error of the last instead of the first
failing pipeline step is both counter-intuitive and useless.
Anyhow, with the PIPSTATUS array at hand, I'm fine anyway. I just
wanted to add my share to help make bash a tiny bit easier to use :-).