tee and exit status

前端 未结 8 1878
礼貌的吻别
礼貌的吻别 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条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 11:45

    #!/bin/sh
    logfile="$1"
    shift
    exec 2>&1
    exec "$@" | tee "$logfile"
    

    Hopefully this works for you.

提交回复
热议问题