Echo newline in Bash prints literal \n

Sergey picture Sergey · Dec 11, 2011 · Viewed 2.3M times · Source

In Bash, tried this:

echo -e "hello\nworld"

But it doesn't print a newline, only \n. How can I make it print the newline?

I'm using Ubuntu 11.04.

Answer

sth picture sth · Dec 11, 2011

You could use printf instead:

printf "hello\nworld\n"

printf has more consistent behavior than echo. The behavior of echo varies greatly between different versions.