2

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
./child.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?

Thanks

0

1 Answer 1

1

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

#!/bin/bash

as the first line of the script.

(The older I get the better I was).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.