Issue
How can I get the name of a child script that is running in the shell of it's parent?
consider script1.sh;
#this is script 1
echo "$0"
. ./script2.sh
and script2.sh;
#this is script 2
echo "$0"
Since script2.sh is being executed in [sourced from] the same shell as script1.sh, the output of running these scripts are both;
./script1.sh
How can get the name of script2.sh within script2.sh?
Solution
You are sourcing a script, not running it. Therefore, you are looking for BASH_SOURCE
.
$ cat test.sh
echo $BASH_SOURCE
$ . ./test.sh
./test.sh
Answered By - ichramm Answer Checked By - Clifford M. (WPSolving Volunteer)