This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _run_deferred() { | |
local _depth="$BASHPID.${#FUNCNAME[@]}" | |
[[ "$_depth" != "$_deferred_depth" ]] && return | |
local opt=$- | |
set +e | |
for (( i=${#_deferred[@]} - 1; i >= 0; i-- )); do | |
eval "${_deferred[i]}" | |
done | |
[[ "$opt" == *e* ]] && set -e | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Bash traceback | |
# | |
# Because the option “set -o errexit” / "set -e" does not show any message when | |
# it stops your Bash script in some cases (for example var=$(yourcommand) will | |
# exit without any message, even when yourcommand returns an exit code | |
# different from zero), I recommend you to add the code below to your bash scripts | |
# to show a traceback each time “errexit” forces your Bash script to stop. | |
# |