Let\'s assume I have 3 shell scripts:
script_1.sh
#!/bin/bash
./script_3.sh
script_2.sh
In case you are source
ing instead of calling/executing the script there is no new process forked and thus the solutions with ps
won't work reliably.
Use bash built-in caller
in that case.
$ cat h.sh
#! /bin/bash
function warn_me() {
echo "$@"
caller
}
$ cat g.sh
#!/bin/bash
source h.sh
warn_me "Error: You didn't do something"
$ . g.sh
Error: You didn't do something 3
g.sh
$
Source