bash-redirections-cheat-sheet icon indicating copy to clipboard operation
bash-redirections-cheat-sheet copied to clipboard

tee can be used to duplicate stdout to stderr

Open frederic-mahe opened this issue 11 years ago • 3 comments

It took me a while to figure it out. As it might be useful for someone else, I propose to add it here.

frederic-mahe avatar Apr 28 '13 17:04 frederic-mahe

Can you show an example here?

pkrumins avatar Apr 29 '13 17:04 pkrumins

Sure:

echo "Foo" | tee /dev/stderr

will print "Foo" twice (on stdout and stderr). I reviewed a script in which the same message was echoed twice: once to the stdout, and a second time to the stderr. To remove that code duplication, I proposed to use the tee command. In my opinion, the interesting reminder here is that you can tee to a file, but also to any other device.

frederic-mahe avatar Apr 29 '13 18:04 frederic-mahe

Cool example! I need to see how it looks in the final cheat sheet. It's tight on space for more examples.

pkrumins avatar May 14 '13 17:05 pkrumins