diff --git a/bin/bash-strict b/bin/bash-strict index aaf8d91..2998b7c 100755 --- a/bin/bash-strict +++ b/bin/bash-strict @@ -6,7 +6,7 @@ TMP_ERROR=$(mktemp -t "$(basename $0).XXXXXXXX" --tmpdir=/run/user/$(id -u)) # FUNCTIONS -function on_exit { +function exit { code=${1:-0} stack_lines=("${BASH_LINENO[@]}") @@ -35,8 +35,8 @@ for i in "${args[@]}"; do args2+=("${i@Q}"); done # echo "----$command ${args2[@]}------" set -TEue -o pipefail -export -f on_exit +export -f exit # echo PROCESS START -bash -c "set -TEue -o pipefail; trap 'on_exit \$? $TMP_ERROR' ERR TERM INT EXIT; source $command ${args2[*]}" 3>&1 1>&2 2>&3 | tee $TMP_ERROR +bash -c "set -TEue -o pipefail; trap 'exit \$? $TMP_ERROR' ERR TERM INT EXIT; source $command ${args2[*]}" 3>&1 1>&2 2>&3 | tee $TMP_ERROR # echo PROCESS END succesfully diff --git a/test5.sh b/test5.sh index c611484..98dfd27 100755 --- a/test5.sh +++ b/test5.sh @@ -2,7 +2,8 @@ ##!/usr/bin/env -S -- bash-strict function f2 { - + # return 6 + # exit 7 unknown_command echo $nope }