diff --git a/bin/bash-strict2.sh b/bin/bash-strict2.sh index c3d4d8c..73045b5 100755 --- a/bin/bash-strict2.sh +++ b/bin/bash-strict2.sh @@ -19,6 +19,15 @@ function exit { $DEBUG && >/dev/tty echo '---stderr---' >&4 echo "DETECTED: [$content]" fi + + stack_lines=("${BASH_LINENO[@]}") + stack_functions=("${FUNCNAME[@]}") + stack_sources=("${BASH_SOURCE[@]}") + + echo "${stack_lines[@]}" + echo "${stack_functions[@]}" + echo "${stack_sources[@]}" + cleanup ${code} } @@ -35,6 +44,7 @@ function cleanup { $DEBUG && >/dev/tty echo "---exit $1---" trap - ERR TERM INT EXIT rm $TMP_ERROR + exec 3>&- 4>&- builtin exit $code } @@ -42,11 +52,9 @@ function cleanup { set -TEue -o pipefail trap 'exit $?' ERR TERM INT EXIT -# export -f exit # magic FD exec 3>$TMP_ERROR 4>/dev/stderr $DEBUG && >/dev/tty echo '---stdout---' source $SCRIPT 2>&3 -exec 3>&- 4>&- success diff --git a/useless.sh b/useless.sh index b788a1c..3b62170 100755 --- a/useless.sh +++ b/useless.sh @@ -1,11 +1,22 @@ #!/bin/bash -echo "stdout A" -# echo toto >>/tmp/toto -# $nope -# exit 6 ->&2 echo "This is stderr" -echo "stdout B" -echo "stdout C" -command_not_found -echo END of useless +function F2 { + echo "stdout A" + # echo toto >>/tmp/toto + # $nope + grep titi toto + # exit 6 + >&2 echo "This is stderr" + echo "stdout B" + echo "stdout C" + # command_not_found +} + +function F1 { + echo F1 + F2 +} + +echo start of useless +F1 +echo end of useless