Bash 如何识别如何运行脚本?
我正在尝试用bash编写简单的脚本。我希望这个脚本能够识别它是如何通过命令行或其他脚本启动的。这是可能的?就像r2evans说的${PPID}是正确的方向: 这就是你想要的:Bash 如何识别如何运行脚本?,bash,Bash,我正在尝试用bash编写简单的脚本。我希望这个脚本能够识别它是如何通过命令行或其他脚本启动的。这是可能的?就像r2evans说的${PPID}是正确的方向: 这就是你想要的: echo "i was called from: $(ps -p $PPID -o command | sed '1d')" 有关解释,请参见man ps、man sed和man bash。PPID在man bash中进行了解释 如果我从testparent脚本调用我的脚本,它如下所示: $ ./te
echo "i was called from: $(ps -p $PPID -o command | sed '1d')"
有关解释,请参见man ps、man sed和man bash。PPID在man bash中进行了解释
如果我从testparent脚本调用我的脚本,它如下所示:
$ ./testparent arg1 arg2
i was called from: /bin/bash ./testparent arg1 arg2
你可以试着从ps-p${PPID}中*推断出,但我不知道你是否/如何能够清楚地知道。