我想获取我正在等待的进程的退出代码并返回它。 我有一个名为 script.sh 的脚本,看起来像这样:
#!/bin/bash
path="/PATH/TO/SCRIPT/another_script.sh"
$path
wait
cleanUpFunction
如何从 script.sh 返回 another_script.sh 的退出代码?
最佳答案
你没有在后台运行 another_script.sh
,所以你根本不需要wait
。
another_script.sh
exit_code=$?
不过,如果您是,wait
的退出状态就是后台进程的退出状态。
another_script.sh &
# Do some other stuff
wait
exit_code=$?
关于linux - Bash 获取等待进程的退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44616562/