【发布时间】:2019-10-22 01:03:16
【问题描述】:
我想从嵌入的 python 代码中退出 shell 脚本。下面的 os.system() 不起作用,其余的 shell 脚本代码仍在执行。
echo "this is shell code"
a=10
python << END
import os
print "this is python code"
if True:
print "yes"
print $a
os.system("exit 1")
END
echo "I am out of python code"
【问题讨论】:
-
简答:你不能那样做。
-
如果 python 脚本(或它调用的任何其他内容)以非零状态退出,您只能通过谷歌搜索 shell 命令
set -e来获取 shell 退出的一种方法。
标签: python bash shell variables