2017-06-18 118 views
1

我想获得我正在等待并返回的进程的退出代码。 我有一个名为script.sh脚本,看起来像这样:Bash获取等待进程的退出代码

#!/bin/bash 

path="/PATH/TO/SCRIPT/another_script.sh" 
$path 
wait 
cleanUpFunction 

如何从script.sh的another_script.sh的退出代码返回?

回答

3

你是不是在后台运行another_script.sh,所以你不需要wait在所有。

another_script.sh 
exit_code=$? 

如果,虽然的wait退出状态是后台进程的退出状态。

another_script.sh & 
# Do some other stuff 
wait 
exit_code=$?