Reputation: 9
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
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