Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15674

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

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: set -e ignored in subshell if part of command list
Date 2019-11-13 11:30 -0500
Message-ID <mailman.1352.1573662614.13325.bug-bash@gnu.org> (permalink)
References <CAMhR0U1fzAvXMVZacEYf9yAPwgq_6Gz5C-99dj6xt=9pQMtX8Q@mail.gmail.com> <13040a55-507d-e072-e827-be7c33be968f@case.edu> <CAMhR0U3yqJ5N-gMCOK7SspOJcdcOCEtu_+cV3=zUgr7fJmkRRQ@mail.gmail.com> <d3c4201b-85d4-eb53-fbd7-ef389f6f7f03@case.edu>

Show all headers | View raw


On 11/13/19 10:59 AM, Shaun Crampton wrote:
> But the commands in the subshell execute inside a different shell
> execution context so they shouldn't have
> their own set -e context (Section 2.12)?

Why? That section says the only thing that changes in the subshell 
environment is signal dispositions.

In fact, the example in the set builtin description explicitly assumes
the subshell inherits the errexit setting. The only thing the standard
requires here is that setting -e in the subshell doesn't change the
parent's setting.

But that's not exactly the point. The shell is "executing any command of an
AND-OR list other than the last" so errexit is ignored.

> 
> I don't see where the spec says that the subshell has to inherit the
> and/or list-ness of the
> parent context.  Section 2.12 doesn't mention that as being one of the
> things that a subshell inherits
> (and unless I'm missing a good use-case, it seems like a pretty
> useless thing to inherit in a subshell
> or a function that happens to be called on the LHS of an and/or).

"A subshell environment shall be created as a duplicate of the shell
environment, except that signal traps that are not being ignored shall be
set to the default action. "

It's an exact duplicate of the shell environment. It's easier to list the
exceptions rather than the long list of things it inherits (more than the
list earlier in that section).

In any event, it's how existing shells behave, and the standard is
attempting to match existing practice. In fact, part of the proposed
language from 2009, when this was debated at length, was "The -e option is
ignored and cannot be enabled by any command run by these lists" but that
was considered unnecessary.

-- 
``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/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: set -e ignored in subshell if part of command list Chet Ramey <chet.ramey@case.edu> - 2019-11-13 11:30 -0500

csiph-web