bug-bash
[Top][All Lists]
Advanced

[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: Fri, 15 Nov 2019 07:57:46 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

On 11/14/19 6:02 PM, Ángel wrote:
On 2019-11-13 at 11:30 -0500, Chet Ramey wrote:
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 would say that the confusing part is that the behavior of the subshell
is dependant on *where* it is being executed in the parent.

In general terms, I would expect
   ( <code> )
to be roughly equivalent to
   bash -c "<code>"

i.e. <code> being executed on its own context and unable to affect the
parent

That's not a good assumption. When the shell executes a command in a
subshell, it forks and executes the command. The subshell is an exact
copy of its parent, so of course it depends on the parent's state at
the time it's created. The subshell being unable to affect the parent's
state is just a consequence of the relationship between processes.
If you want to execute something in a `pristine' environment, you can use
`bash -c' as you showed.

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