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


Groups > gnu.bash.bug > #15671

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

Path csiph.com!tncsrv06.tnetconsulting.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Shaun Crampton <shaun@tigera.io>
Newsgroups gnu.bash.bug
Subject Re: set -e ignored in subshell if part of command list
Date Wed, 13 Nov 2019 15:59:22 +0000
Lines 67
Approved bug-bash@gnu.org
Message-ID <mailman.1348.1573660778.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>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1573660779 1168 209.51.188.17 (13 Nov 2019 15:59:39 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash@gnu.org
To chet.ramey@case.edu
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=tigera.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tj2iZ4OFM7rgScprclaE+t/FiPj6F5UIgF7zW3FcW7Y=; b=YF0bSaO9+d3KQYG5eGQiCWlKs3juNT/XX834kLUux2uaaRJlV7/EgM5ySSwpqJD5nC 5AcsKOssVm1yBgrJyNceHZo75P8/patb4+6WsyvAwkq743DYtSQFdFVh3N8FVsfdqs6g 7aB+siALXdLkL5kTe9E1nYl42pV8g2XElWER8=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tj2iZ4OFM7rgScprclaE+t/FiPj6F5UIgF7zW3FcW7Y=; b=L5BCPl6hMX3dmmEk+WPmh/RH6DCbQCMWl+yOcK4cLqBo10QlJJLR4zsRhGiU9al4+9 mLVVJXQCSh6jhXcvKIiE+utd6g5kXmk8FkS1jNiWjWzW98I4dZ7aszylowKAVwFSWEmk E7nR7LooNUOoGdaaI4wCCzL25wKSSofk9rVPnprNq000CsyiHbVILumWQVTPS8uHAyo7 bgkNb5SxCiB/SQW0unz8Td1ynTCvv0OWGQXLD+j1bSFef36pRiz4BLV5bFz5fQIML5xD IjQm3JZjYYkPWrEsnnrzTViCGvl+YoNEyAdZa8SQCGj1Y3k/puHxsc1WEvF3InsQNv8G JcDQ==
X-Gm-Message-State APjAAAV4KeVMQSFFoZjhp1HJvKQb4KvaTekwThpnykXxxjibbQJSm/OB KSgA9oiQRJrgA3OUq4Vs5M8C99nv1qSatyMqEaLrAw==
X-Google-Smtp-Source APXvYqy7j9zFT5w5qCnoLXasoCF0FIpOCIZJFL5jaeXgXxsniBu6IwhZG4JiFaM+nD+tKSrqbFM+xIWBTJM7lyAnNg4=
X-Received by 2002:ab0:7710:: with SMTP id z16mr2221905uaq.107.1573660773441; Wed, 13 Nov 2019 07:59:33 -0800 (PST)
In-Reply-To <13040a55-507d-e072-e827-be7c33be968f@case.edu>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::935
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAMhR0U3yqJ5N-gMCOK7SspOJcdcOCEtu_+cV3=zUgr7fJmkRRQ@mail.gmail.com>
X-Mailman-Original-References <CAMhR0U1fzAvXMVZacEYf9yAPwgq_6Gz5C-99dj6xt=9pQMtX8Q@mail.gmail.com> <13040a55-507d-e072-e827-be7c33be968f@case.edu>
Xref csiph.com gnu.bash.bug:15671

Show key headers only | View raw


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)?

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).


On Wed, Nov 13, 2019 at 3:07 PM Chet Ramey <chet.ramey@case.edu> wrote:
>
> On 11/13/19 5:24 AM, Shaun Crampton wrote:
>
> > Bash Version: 5.0
> > Patch Level: 3
> > Release Status: release
> >
> > Description:
> >         I was trying to get a function to return early if a command
> > fails by putting
> >         the body of the function in a subshell and using set -e inside
> > the subshell.
> >         If I run a subshell on its own, this works, but when I try to combine it
> >         into a larger program, the set -e gets ignored.
> >
> > Repeat-By:
> >          Managed to boil it down to this smaller example:
> >
> >          # On its own, subshell behaves as expected:
> >          $ ( set -ex; false; echo here )
> >          + false
> >
> >          # In a list, behaviour changes, "echo here" gets executed:
> >          $ ( set -ex; false; echo here ) && echo there
> >          + false
> >          + echo here
> >          here
> >          there
>
> The subshell command is part of an and-or list, so the -e is ignored for
> that command:
>
> "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."
>
> (from
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_03)
>
> The subshell inherits this state (being part of an and-or list) from its
> parent.
>
> >
> >         # If the subshell is executed in the background, it works
> >         $ ( set -e; false; echo here ) & pid=$!; wait $pid && echo there
>
> In this command, the subshell is not part of an and-or list.
>
> --
> ``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 Shaun Crampton <shaun@tigera.io> - 2019-11-13 15:59 +0000

csiph-web