Last active
October 12, 2022 17:30
-
-
Save cardil/810d5471c6617c4391d7f4fe07670f74 to your computer and use it in GitHub Desktop.
Bash scripting pitfall
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 -Eeuo pipefail | |
function error_handler() { | |
local code="${1:-${?}}" | |
abort "🚨 Error (code: ${code}) occurred at ${BASH_SOURCE[1]}:${BASH_LINENO[0]}, with command: ${BASH_COMMAND}" | |
} | |
function abort() { | |
echo "Error: $*" >&2 | |
exit 42 | |
} | |
function sign() { | |
echo 'Signing' | |
false | |
echo 'Signed' | |
} | |
function main() { | |
trap error_handler ERR | |
sign || abort "Failed to sign" | |
# sign | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment