bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: errexit is not suspended in a pipeline


From: Chet Ramey
Subject: Re: errexit is not suspended in a pipeline
Date: Wed, 11 Jan 2023 16:20:52 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1

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    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]