bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status

前端 未结 4 442
离开以前
离开以前 2020-12-23 20:13

To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this:

command 2>&1 | tee -a file.txt
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 20:55

    Perhaps you could put the exit value from PIPESTATUS into $?

    command 2>&1 | tee -a file.txt ; ( exit ${PIPESTATUS} )
    

提交回复
热议问题