I am wondering if there is a way to find out how a file execution was initiated.
For example, consider the following files:
~/foo.sh
echo "Hello from foo.sh"
# print the name of the initiator/parent of this execution
~/bar.sh
source ~/foo.sh
~/baz.sh
. ~/foo.sh
When I execute
sh ~/bar.sh
or .~/bar.sh
, ~/foo.sh
should print ~/bar.sh
sh ~/baz.sh
or .~/baz.sh
, ~/foo.sh
should print ~/baz.sh
I am trying to be generic but it could be specific to bash
or zsh
.
$0
? – ctrl-alt-delor May 01 '20 at 21:08