Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15598
| From | Eli Schwartz <eschwartz@archlinux.org> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: set -e ignored in subshell if part of command list |
| Date | 2019-11-14 18:16 -0500 |
| Message-ID | <mailman.1501.1573773402.13325.bug-bash@gnu.org> (permalink) |
| References | (1 earlier) <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> |
[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
Re: set -e ignored in subshell if part of command list Eli Schwartz <eschwartz@archlinux.org> - 2019-11-14 18:16 -0500
csiph-web