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


Groups > gnu.bash.bug > #15597 > unrolled thread

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

Started byÁngel <angel@debian.16bits.net>
First post2019-11-15 00:02 +0100
Last post2019-11-15 00:02 +0100
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: set -e ignored in subshell if part of command list Ángel <angel@debian.16bits.net> - 2019-11-15 00:02 +0100

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

FromÁngel <angel@debian.16bits.net>
Date2019-11-15 00:02 +0100
SubjectRe: set -e ignored in subshell if part of command list
Message-ID<mailman.1500.1573772923.13325.bug-bash@gnu.org>
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

but the provided case shows that 
  ( set -e; false; echo here ) && echo bar
behaves differently than
  bash -c "set -e; false; echo here" && echo there

since the initial subshell has an advanced knowledge that there will be
a later command joined by an and.

And the fact that reversing the order
  echo hello && ( set -e; false; echo here )

gives a different result, as it is now the *final* element of the &&
list.

The joys of set -e
https://mywiki.wooledge.org/BashFAQ/105, already mentioned in the thread
gives a «funny» read of these things.

Kind regards

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web