echo

Shell (~bash)

Today, an easy one from the list of commands you should know: echo.

Close your eyes for a moment and speculate about what echo does. You’re right!

According to the man page, echo “writes arguments to the standard output”.

> echo Hello, world.
Hello, world.

> echo "Hello, world."
Hello, world.

> echo "Hello, world." "Foo"
Hello, world. Foo

By default, echo adds a newline at the end of its output. For writing things to the screen, this is likely exactly what you want. (Yay!) However, if you’re planning to pipe echo’s output to some other commands input, you might not want the newline.

Enter -n:

> echo mySecretPassw0rd | shasum 
0f7262d74d2d48c30121c7e80a5bda5d22968a32  -

> echo -n mySecretPassw0rd | shasum
de72bcbdefa256e34fac7fb0abe08b43aa54df49  -

That’s it…echo only has the one option. It does one thing…and it does it well. It’s handy in scripts and in the middle of one-liners. It’s less handy by itself.

Published: November 01 2012

Author: trimble