Skip to content

Instantly share code, notes, and snippets.

@lexton
Last active October 18, 2016 05:26
Show Gist options
  • Save lexton/aa0ab5e8f4b5c3e6da2108274da8e4f2 to your computer and use it in GitHub Desktop.
Save lexton/aa0ab5e8f4b5c3e6da2108274da8e4f2 to your computer and use it in GitHub Desktop.
Printing a stack trace in bash
#!/bin/bash
fatal() {
local frame=0
while caller $frame; do
((frame++));
done
echo "$*"
exit 1
}
f1(){
undefined_command
if [ $? -ne 0 ]; then
fatal "things went bad."
fi
}
f2(){
f1
}
f3(){
f2
}
f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment