From 8a54cd1374b8791e7c91c5412ce50ab93f616dad Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 16 Apr 2021 15:14:05 +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: I26396b87d4a391a75997c061e866709daa57870e --- templates/scripts/includes/deployment.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/scripts/includes/deployment.sh b/templates/scripts/includes/deployment.sh index bdf6134..565a03f 100755 --- a/templates/scripts/includes/deployment.sh +++ b/templates/scripts/includes/deployment.sh @@ -3,6 +3,7 @@ ################################################################################ set -e +set -E # Functions