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

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

./aaa.sh | tee bbb.out

How would I now also write standard error to a file named ccc.out, while still having it displayed?

12 s
12

Simply:

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

This simply redirects standard error to standard output, so tee echoes both to log and to the 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

Leave a Comment