3 ms·
If your script dies because of `set -e` the detective work is just the punishment to condition yourself to write more stable code in the future ;-) By the way,
by arendtio 8y ago
If your script dies because of `set -e` the detective work is just the punishment to condition yourself to write more stable code in the future ;-)
By the way, if you are just using Bash (instead of POSIX /bin/sh) you can do even better. Some time ago I found a stacktrace function somewhere:
set -Eeuo pipefail
trap stacktrace EXIT
function stacktrace {
if [ $? != 0 ]; then
echo -e "\nThe command '$BASH_COMMAND' triggerd a stacktrace:"
for i in $(seq 1 $((${#FUNCNAME[@]} - 2))); do j=$(($i+1)); echo -e "\t${BASH_SOURCE[$i]}: ${FUNCNAME[$i]}() called in ${BASH_SOURCE[$j]}:${BASH_LINENO[$i]}"; done
fi
}