Created
March 9, 2012 14:52
-
-
Save bluegraybox/2006836 to your computer and use it in GitHub Desktop.
Stack traces in bash
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
#!/bin/bash | |
function stacktrace() { | |
frame=0 | |
while caller $frame ; do frame=$((frame + 1)) ; done | |
} | |
function lib_inner() { | |
stacktrace | |
} | |
function lib_outer() { | |
lib_inner | |
} |
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
$ ./test.sh | |
9 lib_inner ./lib.sh | |
13 lib_outer ./lib.sh | |
8 inner ./test.sh | |
12 outer ./test.sh | |
15 main ./test.sh |
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
function stacktrace() { | |
frame=0 | |
while caller $frame ; do frame=$((frame + 1)) ; done | |
} |
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
#!/bin/bash | |
dir=`dirname $0` | |
. $dir/lib.sh | |
function inner() { | |
lib_outer | |
} | |
function outer() { | |
inner | |
} | |
outer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This makes less sense in alphabetical order.