Home > Software engineering >  bash cat pipe supposedly misbehaving
bash cat pipe supposedly misbehaving

Time:04-29

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.

CodePudding user response:

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.

  • Related