gpt4 book ai didi

linux - 如何检测是否从另一个 shell 脚本调用了 shell 脚本

转载 作者:太空狗 更新时间:2023-10-29 11:12:55 25 4
gpt4 key购买 nike

<分区>

有没有办法检测 shell 脚本是直接调用还是从另一个脚本调用。

parent.sh

#/bin/bash
echo "parent script"
./child.sh

child.sh

#/bin/bash
echo -n "child script"
[ # if child script called from parent ] && \
echo "called from parent" || \
echo "called directly"

结果

./parent.sh
# parent script
# child script called from parent

./child.sh
# child script called directly

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com