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


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

set -e ignored in subshell if part of command list

Started byShaun Crampton <shaun@tigera.io>
First post2019-11-13 10:24 +0000
Last post2019-11-13 10:24 +0000
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

  set -e ignored in subshell if part of command list Shaun Crampton <shaun@tigera.io> - 2019-11-13 10:24 +0000

#15668 — set -e ignored in subshell if part of command list

FromShaun Crampton <shaun@tigera.io>
Date2019-11-13 10:24 +0000
Subjectset -e ignored in subshell if part of command list
Message-ID<mailman.1340.1573656062.13325.bug-bash@gnu.org>
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 )

[toc] | [standalone]


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


csiph-web