Last active
August 23, 2022 07:49
-
-
Save jonatanblue/f1109b4b97752bed4e70b7d17366c67f to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -o pipefail -o errtrace -o errexit -o nounset | |
shopt -s inherit_errexit | |
[[ -n "${TRACE:-}" ]] && set -o xtrace | |
trap 'stacktrace "Error trapped rc=${PIPESTATUS[@]}, see trace above"' ERR | |
stacktrace() { | |
local frame="${#FUNCNAME[@]}" | |
echo >&2 "Stacktrace:" | |
while [[ "${frame}" -gt 1 ]]; do | |
((frame--)) | |
echo >&2 " File ${BASH_SOURCE[$frame]}#L${BASH_LINENO[$((frame - 1))]} (in ${FUNCNAME[$frame]}())" | |
done | |
if [[ "$#" -gt 0 ]]; then | |
echo >&2 "$1" | |
fi | |
} | |
greetings() { | |
echoo "TRUE" | |
} | |
good() { | |
local res | |
res="$(greetings)" | |
if [[ "${res}" == "TRUE" ]]; then | |
echo "Hello, world!" | |
else | |
echo "Goodbye, world!" | |
fi | |
} | |
bad() { | |
if [[ "$(greetings)" == "TRUE" ]]; then | |
echo "Hello, world!" | |
else | |
echo "Goodbye, world!" | |
fi | |
} | |
main() { | |
bad | |
} | |
main "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment