user13805602
user13805602

Reputation: 9

How to recognize how to run script?

i'm trying write easy script in bash. I'd like to this script recognizes how to it has launched, command line or by another script. It is possible?

Upvotes: 0

Views: 37

Answers (1)

Oliver Gaida
Oliver Gaida

Reputation: 1930

like r2evans said ${PPID} is the right direction:

that is what you want:

echo "i was called from: $(ps -p $PPID -o command | sed '1d')"

see man ps, man sed and man bash for explanations. The PPID is explained in man bash.

If I call my script from the testparent script, it looks like this:

$ ./testparent arg1 arg2
i was called from: /bin/bash ./testparent arg1 arg2

Upvotes: 1

Related Questions