Multiple echo commands that are piped


New Member
Hi, I am beginner to Linux and have a question.
Echo xyz printing xyz
Echo abc | echo xyz printing xyz. Why not abc instead of xyz?


Well-Known Member
"abc" is not echoed to the screen. Instead, the pipe echoes "abc" to the second command, which is "echo xyz".
But the piped data from the first command does nothing in the second command. Which it is why it doesn't appear after the second command.

If you used xargs:
echo abc | xargs echo xyz
You would get the following echoed to the screen:
xyz abc
Because "abc" would be piped to xargs and would then be used as a parameter to the second echo command.

So it would be equivalent to typing the command:
echo xyz abc

Members online

Latest posts