0

I have two scripts: script1.sh and script2.sh. script1.sh is executing script2.sh. This is how it looks like:

#!/bin/bash
./script2.sh

How to show in script2.sh by which script was executed? For example

./script1.sh

and then I have an output

script2.sh was executed by script1.sh
user3461823
  • 1,303
  • 2
  • 11
  • 17
  • [What problem are you trying to solve?](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) You can pass calling script name as the first argument like this: `./script2.sh ${BASH_SOURCE[0]}` – yeputons Feb 03 '17 at 09:32
  • Hi yeputons, Yes I could, but I have many "parents" scripts which invoke one child script and I don't want to change their content. – user3461823 Feb 03 '17 at 09:35
  • assuming script 1 does not exit before script 2 completes, you could have script 2 get its parent process id (ppid) with something like " myppid=`ps -p ${pid:-$$} -o ppid=` " then have the script use that to get the caller name. – General Foch Feb 03 '17 at 15:07

0 Answers0