tee and exit status

前端 未结 8 1872
礼貌的吻别
礼貌的吻别 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:34

    This works with bash:

    (
      set -o pipefail
      mycommand --foo --bar | tee some.log
    )
    

    The parentheses are there to limit the effect of pipefail to just the one command.

    From the bash(1) man page:

    The return status of a pipeline is the exit status of the last command, unless the pipefail option is enabled. If pipefail is enabled, the pipeline's return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully.

提交回复
热议问题