Multiple echo commands that are piped

Anji

New Member
Joined
Jul 3, 2019
Messages
1
Reaction score
0
Credits
0
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?
 


"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


Top