Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15668
| From | Shaun Crampton <shaun@tigera.io> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | set -e ignored in subshell if part of command list |
| Date | 2019-11-13 10:24 +0000 |
| Message-ID | <mailman.1340.1573656062.13325.bug-bash@gnu.org> (permalink) |
| References | <CAMhR0U1fzAvXMVZacEYf9yAPwgq_6Gz5C-99dj6xt=9pQMtX8Q@mail.gmail.com> |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-LQgi2O/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux shauns-laptop 5.1.16-050116-generic #201907031232
SMP Wed Jul 3 12:35:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
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
# If the subshell is executed in the background, it works
$ ( set -e; false; echo here ) & pid=$!; wait $pid && echo there
[1] 26219
[1]+ Exit 1 ( set -e; false; echo here )
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
set -e ignored in subshell if part of command list Shaun Crampton <shaun@tigera.io> - 2019-11-13 10:24 +0000
csiph-web