更新时间:2023-12-05 19:56:28
使用数组PIPESTATUS:
Use array PIPESTATUS:
Python script.py 2>&1 | tee /logfile.log
ret="${PIPESTATUS[0]}"
if [[ "$ret" -ne "0" ]]; then
exit "$ret"
fi
来自man bash
:
PIPESTATUS
:一个数组变量(请参见下面的数组),其中包含最 最近执行的前台管道(可能仅包含一个命令).
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).