bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

set -e ignored in subshell if part of command list


From: Shaun Crampton
Subject: set -e ignored in subshell if part of command list
Date: Wed, 13 Nov 2019 10:24:23 +0000

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 )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]