Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

bash cat pipe supposedly misbehaving

In the following, I have made echo to write to stderr; then it’s piped to cat, which has both output streams connected to /dev/null.

$ echo something 1>&2 | cat 2>&1 >/dev/null
something

All in all, nothing should be printed. As it turns out, something still gets printed!

Can someone please explain what’s happening here? TY.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As you write the output to stderr, it displays the output. If you would write it to stdout, it would not display the output.
This image from the wikipedia article about pipes explains it very well

Pipeline Flow from wikipedia

For more information read the Wikipedia article about Pipelines in Linux.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading