Created
May 14, 2012 03:17
-
-
Save mpdaugherty/2691574 to your computer and use it in GitHub Desktop.
A test file that illustrates the use of $BASH_SOURCE and $FUNCNAME
This file contains hidden or 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 f1() { | |
echo 'In f1' | |
echo '' | |
echo ${BASH_SOURCE[0]} + ${FUNCNAME[0]} | |
echo ${BASH_SOURCE[1]} + ${FUNCNAME[1]} | |
} | |
echo 'in bash_source_test.sh' | |
echo '' | |
echo ${BASH_SOURCE[0]} + ${FUNCNAME[0]} | |
echo '' |
This file contains hidden or 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
mpdaugherty@grit ~ $ ./bash_source_test.sh | |
in bash_source_test.sh | |
./bash_source_test.sh + | |
In f1 | |
./bash_source_test.sh + f1 | |
./bash_source_test.sh + main |
This file contains hidden or 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
mpdaugherty@grit ~ $ source bash_source_test.sh | |
in bash_source_test.sh | |
bash_source_test.sh + | |
In f1 | |
bash_source_test.sh + f1 | |
bash_source_test.sh + source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed to add a call to f1 as the last line of the script to get the same result as you show.