On 1/11/23 4:04 PM, Quinn Grier wrote:
On 2023-01-11 06:44, Chet Ramey wrote:
On 1/10/23 9:36 PM, Quinn Grier wrote:
In the documentation for set -e, the Bash manual says that errexit is
suspended in all but the last command of a pipeline:

        The shell does not exit if the command that fails is part of
        [...] any command in a pipeline but the last

I'm not sure why you included the `part of' in your quote, since it clearly
applies to the text following it: "part of the command list immediately
following as while or until keyword, part of the test following ..."

I agree, my quotation of that documentation is wrong, as "part of" does
not apply to "any command in a pipeline". However, I still think my
example script shows something fishy.

Here's another example script that might help show what I mean. This one
goes through all of the apparent contexts where set -e is ignored:

They are not all contexts where set -e is ignored. There is a distinction
between the effect of -e being ignored and the shell not exiting when a
command fails.

If you don't like the bash manual page wording, here's what POSIX says:

"1. The failure of any individual command in a multi-command pipeline shall not cause the shell to exit. Only the failure of the pipeline itself shall be considered.

2. The -e setting shall be ignored when executing the compound list following the while, until, if, or elif reserved word, a pipeline beginning with the ! reserved word, or any command of an AND-OR list other than the last.

3. If the exit status of a compound command other than a subshell command was the result of a failure while -e was being ignored, then -e shall not apply to this command.

This requirement applies to the shell environment and each subshell environment separately. For example, in:

set -e; (false; echo one) | cat; echo two

the false command causes the subshell to exit without executing echo one; however, echo two is executed because the exit status of the pipeline (false; echo one) | cat is zero."


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/


Reply via email to