From ae34398b3adf4e7e8f62abbc203508d4ce9f5a21 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 16 Apr 2021 15:12:08 +0200 Subject: [PATCH] TT#119602 Properly handle trap also in case of errors in functions Quoting from "man bash" about `-E` (AKA errtrace): | If set, any trap on ERR is inherited by shell functions, command | substitutions, and commands executed in a subshell environment. | The ERR trap is normally not inherited in such cases. To demonstrate the problem see this short shell script: | % cat foo | set -eu -o pipefail | | bailout() { | echo "Bailing out because of error" >&2 | exit 1 | } | trap bailout 1 2 3 6 9 14 15 ERR | | foo() { | echo "Executing magic" | magic | } | | foo | echo end If "magic" can't be executed, then this fails as follows: | % bash ./foo | Executing magic | ./foo: line 11: magic: command not found But it doesn't invoke the bailout function via trap. When using `set -eE` (AKA errexit + errtrace), instead of only `set -e` (errexit), then it behaves as expected though: | % bash ./foo | Executing magic | ./foo: line 11: magic: command not found | Bailing out because of error Change-Id: I3feca2af2276cd64cd17f8768eb9bf130e170f92 --- ngcp-system-tests | 1 + 1 file changed, 1 insertion(+) diff --git a/ngcp-system-tests b/ngcp-system-tests index 4697515..7005b56 100755 --- a/ngcp-system-tests +++ b/ngcp-system-tests @@ -1,6 +1,7 @@ #!/bin/bash set -e +set -E declare -r ME="$(basename "$0")" declare -r OPTS=("$@")