2017-06-18 114 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=$?