Echo newline in Bash prints literal \n

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 (Natty Narwhal).


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.

Leave a Comment