tee and exit status

前端 未结 8 1870
礼貌的吻别
礼貌的吻别 2021-02-07 10:43

is there an alternative to \"tee\" which captures STDOUT/STDERR of the command being executed and exits with the same exit status as the processed command. Something as followin

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 11:29

    Korn shell, ALL in 1 line:

    foo; RET_VAL=$?; if test ${RET_VAL} != 0;then echo $RET_VAL; echo Error occurred!>/tmp/out.err;exit 2;fi |tee >>/tmp/out.err ; if test ${RET_VAL} != 0;then exit $RET_VAL;fi
    

提交回复
热议问题