【发布时间】:2019-08-04 09:40:24
【问题描述】:
按照 Cyrus 的建议扩展 question,我想知道如果我将其发送到后台运行,是否可以使用 PIPESTATUS 或类似的东西跟踪相同的脚本?
bash 脚本如下:
#! /bin/bash
{ python script.py 2>&1 | tee logfile.log; } &
ret="${PIPESTATUS[0]}"
if [[ "$ret" -ne "0" ]]; then
echo "$ret"
fi
而script.py 是:
print("hello")
exit(1);
print("world")
当我在没有& 的情况下运行bash 脚本时,它会正确打印PIPESTATUS,但如果我在后台运行它,则不会返回任何输出。
【问题讨论】:
-
它是,但在子外壳内部,而不是外部。
标签: bash pipestatus