When I run the following Bash
script, I would expect it to print Hello
. Instead, it prints a blank line and exits.
echo 'Hello' | echo
Why doesn't piping
output from echo
to echo
work?
echo
prints all of its arguments. It does not read from stdin
. So the second echo
prints all of its arguments (none) and exits, ignoring the Hello
on stdin
.
For a program that reads its stdin
and prints that to stdout
, use cat
:
$ echo Hello | cat
Hello