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

why does "echo "qwerty" | /bin/sh" return "/bin/sh: 1: qwerty: not found"?

I know that echo command displays the line of text that is passed as argument.

So the syntax echo "qwerty" would display:

qwerty

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

but when I merge the previous syntax with | /bin/sh the following message is displayed:

/bin/sh: 1: qwerty: not found

I would like to know why using bitwise OR operator (i.e. | ) this way ending up with such an output.

>Solution :

| is not a bitwise OR operator.[1] It’s a pipe operator. It causes the stdout of the preceding program to be piped to the stdin of the following program.

$ printf 'abc def\nghi\n' | wc
      2       3       12

This shows wc ("word count") reading the output of printf and printing out the fact that it received 2 lines, 3 words and 12 bytes.

In your case, sh reads its stdin for commands (due to the absence of both a -c option and a file name argument), and thus treats qwerty as a command to execute.


  1. It can be bitwise OR in arithmetic context when using bash and possibly other shells in the "sh family". That’s not the case here even if you were using bash.
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