Possible Duplicate:
In the bash script how do I know the script file name?
How can you access the base filename of a file you are sourcing in Bash
When using source
to call a bash script from another, I'm unable to find out from within that script what the name of the called script is.
file1.sh
#!/bin/bash
echo "from file1: $0"
source file2.sh
file2.sh
#!/bin/bash
echo "from file2: $0"
Running file1.sh
$ ./file1.sh
from file1: ./file1.sh # expected
from file2: ./file1.sh # was expecting ./file2.sh
Q: How can I retrieve file2.sh
from file2.sh
?