• Important: We recently upgraded our forum software - please let us know if you run into any issues.

Multiple echo commands that are piped

Anji

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?
 


JasKinasis

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:
Code:
echo abc | xargs echo xyz
You would get the following echoed to the screen:
Code:
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:
Code:
echo xyz abc
 

Members online


Latest posts


Top