Hello.
I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors?
Thanks
I don't think that you can do that through a command. May be something like this?
# cat test.sh
#!/usr/bin/ksh
func1() {
echo global function
echo $(ps -ef |awk -v pid=$$ '{if($2==pid) print $NF}') has run func1
}
# cat test1.sh
#!/usr/bin/ksh
. ./test.sh
echo $0 is running
func1
echo $0 is ending
# ./test1.sh
./test1.sh is running
global function
./test1.sh has run func1
./test1.sh is ending
Here test.sh holds the global function, test1.sh 'sources' test.sh via the '. ./' mechanism.
Note: on Solaris, please use nawk instead of awk.