使用tee时获取exitcode

当使用tee时,程序的exitcode无法正常获取,比如a.out的exitcode为1,但是使用tee之后得到的为0。这时可以使用set -o pipefail,如下:

./a.out | tee
echo $? # 0

set -o pipefail
./a.out | tee
echo $? # 1



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • DeepSeek-V4 实测:谦虚的官方,靠谱的模型
  • Claude有多大?从推理速度反推参数量
  • TurboQuant:一篇论文砸崩存储股价?MNN在手机上跑通了
  • Google Stitch 体验:解决 CC 写 UI 的痛
  • MNN 任务实测:七个模型,三个梯队