我无法通过 "timeout comand" 获得 "exit status"
I can not get "exit status" with "timeout comand"
我希望得到 "status 124",但是用下面的代码得到了 "status 0"
timeout 10 sleep 20 | tee -a LOG_FILE LOG_FILE2
RET=$?
echo $RET
我通过使用此代码获得了 "status 0"。
我希望得到"status 124"。
这段代码发生了什么
$?
保存最后一个管道的退出状态。使用 PIPESTATUS
获取前台管道的退出状态(在本例中为 timeout
命令)。
$ timeout 10 sleep 20 | tee -a LOG_FILE LOG_FILE2
$ RET=${PIPESTATUS[0]}
$ echo $RET
124 # timed out
男人bash
PIPESTATUS: An array variable (see Arrays below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).
我希望得到 "status 124",但是用下面的代码得到了 "status 0"
timeout 10 sleep 20 | tee -a LOG_FILE LOG_FILE2
RET=$?
echo $RET
我通过使用此代码获得了 "status 0"。
我希望得到"status 124"。
这段代码发生了什么
$?
保存最后一个管道的退出状态。使用 PIPESTATUS
获取前台管道的退出状态(在本例中为 timeout
命令)。
$ timeout 10 sleep 20 | tee -a LOG_FILE LOG_FILE2
$ RET=${PIPESTATUS[0]}
$ echo $RET
124 # timed out
男人bash
PIPESTATUS: An array variable (see Arrays below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).