Piping not working with echo command

Elliot A. picture Elliot A. · Jan 31, 2016 · Viewed 79.8k times · Source

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?

Answer

iobender picture iobender · Jan 31, 2016

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