Pipe output and capture exit status in Bash

后端 未结 15 1361
盖世英雄少女心
盖世英雄少女心 2020-11-22 08:07

I want to execute a long running command in Bash, and both capture its exit status, and tee its output.

So I do this:

command | tee out.txt
ST=$?
         


        
15条回答
  •  借酒劲吻你
    2020-11-22 08:29

    using bash's set -o pipefail is helpful

    pipefail: the return value of a pipeline is the status of the last command to exit with a non-zero status, or zero if no command exited with a non-zero status

提交回复
热议问题