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