echo: And an inescapable fragment of history

After much internal debate, I decided to include echo in this august parade. echo hardly does anything, but I use it so much that it would be a glaring omission if I didn’t include it.

You probably already know what echo is for: It outputs a string of text. That’s the first line of the man page, after all.

kmandla@6m47421: ~$ echo Hello world.
Hello world.

And now you’ve seen all that echo does … mostly.😉

Like any good tool, it has a few things you can customize. For starters there is an -n flag, which prevents echo from breaking to a new line when it finishes. In other words:

kmandla@6m47421: ~$ echo -n Hello world.
Hello world.kmandla@6m47421: ~$ 

echo can also do some funny things, if you allow it with the -e flag. The man page has a full list, but for example, line feeds are possible. A line feed is not a newline, as this should show:

kmandla@6m47421: ~$ echo -e "Hello \fworld."
Hello 
      world.

And line feeds are not carriage returns, as this should show:

kmandla@6m47421: ~$ echo -e "Hello there, \rworld."
world.there,

If you remember computers from way, waaay back, you probably already knew the difference. If you don’t it might help to imagine a printer head moving across a page. Line feeds advance the paper without moving the head, and carriage returns bring the printer head back to the starting edge without advancing the paper. Put both of them together and you have a newline. And of course, all of this evolved from the days of manual typewriters, when your printer was 168cm tall and took coffee breaks twice a day.

I’ll leave it to you to explore all the subtleties of echo; there aren’t many, but it is a utility that you can use on a daily basis and still not see every option. And of course, echo is part of the world-famous coreutils suite.🙂

4 thoughts on “echo: And an inescapable fragment of history

  1. Jon Doe

    echo -n >emptyfile
    to create an empty file or delete the content of a file, if it exists
    echo -n >>file
    to make sure a file exists (like touch)
    echo *
    to show files without ls
    echo $PATH
    to show the content of $PATH

  2. Pingback: Links 24/9/2014: GNOME 3.14 Released, Bash Has a Bug | Techrights

  3. Pingback: Tricks of the trade | Motho ke motho ka botho

Comments are closed.