How do I write stderr to a file while using “tee” with a pipe?

前端 未结 10 945
独厮守ぢ
独厮守ぢ 2020-11-22 08:01

I know how to use tee to write the output (STDOUT) of aaa.sh to bbb.out, while still displaying it in the terminal:

10条回答
  •  北海茫月
    2020-11-22 08:41

    why not simply:

    ./aaa.sh 2>&1 | tee -a log
    

    This simply redirects stderr to stdout, so tee echoes both to log and to screen. Maybe I'm missing something, because some of the other solutions seem really complicated.

    Note: Since bash version 4 you may use |& as an abbreviation for 2>&1 |:

    ./aaa.sh |& tee -a log
    

提交回复
热议问题