CentOS/RHEL 7. GNU bash, version 4.2.46(2)-release

I have two bash scripts, lets call them parent.sh and child.sh. The parent just calls the child thus:

# parent.sh

and in child.sh I want to see the actual name of the parent script. I have tried grabbing the info from /proc but I keep getting just "-bash" returned. Here is a sample of the child.sh:

# child.sh
echo "My process ID is: $$"
echo "or is it $BASHPID"
echo "My Parent ID is: $PPID"
echo "Par Cmd: " `cat /proc/$PPID/cmdline`
PARENT=$(ps -o args= $PPID)
echo "Or is it: " $PARENT 

echo "Press any key to continue..........."
read x

When I run parent.sh I see this:

$ ./parent.sh 
$ ./parent.sh 
My process ID is: 14634
or is it 14634
My Parent ID is: 14633
Par Cmd:  -bash
Or is it:  -bash
Press any key to continue...........

What I need to get is the actual name of the script that invoked child.sh - I expect to see (at least in part) "parent.sh"

Can anyone point me in the right direction please?



1 Answer 1


Solved it myself. All I had to do was to put the


as the first line of the script.

(The older I get the better I was).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .