如何检查是从终端还是从其他脚本调用脚本

时间:2018-05-11 01:37:16

标签: python linux bash ubuntu

我正在编写一个python脚本,我想只在python脚本直接从终端运行而不是从任何其他脚本运行时执行一些代码。

如何在不使用任何额外命令行参数的情况下在Ubuntu中执行此操作。?

这里的答案不工作Determine if the program is called from a script in Python

这是我的目录结构

home |-testpython.py |-script.sh

script.py包含

./testpython.py

当我跑./script.sh时,我希望有一件事情发生。 当我直接从终端运行./testpython.py而不调用“script.sh”时,我想要其他事情发生。

我如何在调用方式中检测到这种差异。获取父进程名称始终返回“bash”本身。

0 个答案:

没有答案
相关问题