bash-redirections-cheat-sheet
bash-redirections-cheat-sheet copied to clipboard
tee can be used to duplicate stdout to stderr
It took me a while to figure it out. As it might be useful for someone else, I propose to add it here.
Can you show an example here?
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.
Cool example! I need to see how it looks in the final cheat sheet. It's tight on space for more examples.