[Top][All Lists]

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

Re: set -e ignored in subshell if part of command list

From: Chet Ramey
Subject: Re: set -e ignored in subshell if part of command list
Date: Wed, 13 Nov 2019 11:43:53 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

On 11/13/19 10:59 AM, Andrew Church wrote:
"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."


The subshell inherits this state (being part of an and-or list) from its

Is that really the intent of the requirement, though?


The same section
states: "This requirement applies to the shell environment and each
subshell environment separately", which I read to mean that the rules
should be evaluated without consideration of any parent or subshell
environment other than the one in which the -e option is being applied.

Not quite. It means that the reasons a subshell (for instance) exits may
not be the same ones applied to the parent.

And the example:

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

shows rule 1 ("The failure of any individual command in a multi-command
pipeline shall not cause the shell to exit")

OK. The "individual command" in this context is the subshell command. The
subshell command exits with a non-zero status, but that doesn't cause the
shell to exit. The -e setting isn't ignored in the subshell because it's not in an and-or list.

not being applied within
the subshell, even though the subshell as a whole is an "individual
command in a multi-command pipeline".  I don't see any suggestion that
the case of an AND-OR list in rule 2 should be treated differently, and
absent an explicit requirement one way or the other, I think the
expected behavior here would be that the behavior of the subshell is
independent of the subshell's context in the parent shell.

The "-e setting shall be ignored" part? Expectations aside, that's just not
how shells behave, and not the intent of the standard. This was discussed
pretty thoroughly back in 2009, and shell behavior reflects the consensus
from that discussion. As I said in another message, there was a proposal
for some stronger language ("-e is disabled and cannot be re-enabled when
executing...any command of an AND-OR list except the last" is another
version of the proposed language) but that was deemed unnecessary.

The relevant interpretation was http://austingroupbugs.net/view.php?id=52
but there's not much discussion there -- it was all on the mailing list.

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

reply via email to

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