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


Groups > gnu.bash.bug > #15598

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

Path csiph.com!weretis.net!feeder6.news.weretis.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Eli Schwartz <eschwartz@archlinux.org>
Newsgroups gnu.bash.bug
Subject Re: set -e ignored in subshell if part of command list
Date Thu, 14 Nov 2019 18:16:24 -0500
Lines 97
Approved bug-bash@gnu.org
Message-ID <mailman.1501.1573773402.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> <1573772541.924.11.camel@debian.16bits.net> <aa7ba22d-94d3-3a4a-da2f-5439580d3dd3@archlinux.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Vul2RclUoPftRmz68LvbOTf7J1aw0MJ5h"
X-Trace usenet.stanford.edu 1573773403 1135 209.51.188.17 (14 Nov 2019 23:16:43 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1573773387; bh=xhuKI6wvw3/hpYaMt5p4orQTAVgSP62HmJsiubpjE/k=; h=Subject:To:References:From:Date:In-Reply-To; b=BQntkRsVmNsj4qaHKUKi7SEils0S4kRrrnLamly0n1jOeMWx8qCkaj2VUd+KKqDGo n8qMQ8FPc6AfSz+0o7NbDcrnJPIwWsdA+E6cWWWf/zMjtpeQGJQMhzdLZ87Ni87n/h SIt9qaXdcI6TLqShcnQq0skhjQXImcFprJTHxUmUumKGg481LguAXgVyoSXmFV/2pv mjohuODqFU3wFVUi+ACXv9eFeD89l2NCKwBPvOzkbNrOJf7SVg6lClBgEu8c52dw+7 if8L07/lm0XWmxyRMqGYq4/Ze+gtS4kjft+ao1pFHf0z8lu7qkoY+F3IBEaobu5MhC YU8fyx4+I/q1BXJb5a40ojAy+I/EdzpQZKj6K52tSnEmfmUnhZe7vgHVzBpOYvwFTs aKY3kUQHPQv+fK/dU8+4l0533O3GpPy2cQAiMyF/7P4pdEIzdQh9kklqPkYLsc1TEf RrE1PXvgv5eriXKDZjT7kZNtXcJqWEYbuMIxaUfRtNQAKZqKbcsmvQekaidJs5vdkQ 1gJgR05+4MF4uYaOAlMhzpEeYEY58TzfBh/74dpF6xh+/U16ft3mz0pnJUwIiToWZb /Y1seeg4DYOy+THwO1Zk8rdOwVYwjSeW7Z9yGZYHSdLM3ryOz80NdTjfgvXZiNvjqX tSyWYWdHnr8Kwn7tv7m5GC7g=
X-Clacks-Overhead GNU Terry Pratchett
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2
In-Reply-To <1573772541.924.11.camel@debian.16bits.net>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2a01:4f8:160:6087::1
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 <aa7ba22d-94d3-3a4a-da2f-5439580d3dd3@archlinux.org>
X-Mailman-Original-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> <1573772541.924.11.camel@debian.16bits.net>
Xref csiph.com gnu.bash.bug:15598

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 11/14/19 6:02 PM, Ángel wrote:
> 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 that's totally wrong for *numerous* reasons.

> 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

What about

var=value; (echo "$var")

which behaves differently from

var=value; bash -c 'echo "$var"'

or,

func() { echo "hi there"; }; (func)

which behaves differently from

func() { echo "hi there"; }; bash -c 'func'

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

An initial subshell has advanced knowledge about lots of things from the
parent shell, it is deeply, worryingly dangerous to write code that
doesn't take this into account. Things will tend to go pretty badly wrong.

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

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


Thread

Re: set -e ignored in subshell if part of command list Eli Schwartz <eschwartz@archlinux.org> - 2019-11-14 18:16 -0500

csiph-web