ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline?
I have searched "Linux newbie" for "echo" in titles, but no answer to my question is found.
when I learnt pipeline of Bash, I tried: ls | echo , which I would like to see the same result of the "ls". The output of "ls" is redirected to the 2nd command "echo" and be its argument, that's what I thought. But the output is blank. If I use: echo $(ls) instead, I get what I want, like this, echo $(ls) a.txt b.txt So, does someone know why echo can't take the output of the previous command in a pipeline? Thanks elinuxqs |
echo doesn't read input from stdin, so you can't pipe data into it. If you want to transform stdin to arguments for echo, use xargs, like this:
Code:
ls | xargs echo Code:
echo * Code:
echo \* Code:
ls -l '*' Code:
ls: *: No such file or directory Code:
ls |cat |
Quote:
|
Thank you ^^ matthewg42 and soggycornflake
matthewg42, you're cool. Bash reference doesn't tell me how echo works, so I was confused. Thank you. elinuxqs |
echo was originally an external command, and that command had/has it's own manual page. Because it is something which tends to be used pretty frequently, and is simple, it was adopted by more modern shells as an internal command (this makes it more efficient to call since there is no spawning of a new process for the external program).
This leads to the rather confusing situation with modern distros where you have both the program in /bin/echo, with it's own manual page, but when you type "echo something" in a bash shell, the bash-internal is used, and the behaviour is sligtly different to that which the manual page describes: Code:
$ echo --version |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 11:43 AM. |