Skip to content

Instantly share code, notes, and snippets.

@andrewgross
Created August 20, 2012 23:29
Show Gist options
  • Save andrewgross/3409237 to your computer and use it in GitHub Desktop.
Save andrewgross/3409237 to your computer and use it in GitHub Desktop.
Bash Callstack
# If for some insane reason we really want to inspect the bash callstack
# we can use the BASH_LINENO, BASH_SOURCE and FUNCNAME variables
my_function() {
echo "My Function Name: ${FUNCNAME[0]}, I am at line ${BASH_LINENO[0]} of file ${BASH_SOURCE[0]}"
# Unless we call this from deeper down, we will get `main`, line 0, and the same filename as before
echo "My Parent Function: ${FUNCNAME[1]} is at line ${BASH_LINENO[1]} of file ${BASH_SOURCE[1]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment