Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jan 012010
 

How to print out a newline character using the echo command?

Answer:

If you try

echo "foo\nbar"

It will print out

foo\nbar

But if you want the two words separate by an actual newline, you can use

echo -e "foo\nbar"

Output would be

foo
bar

You can combine the "-e" flag with other control characters such as "\t", "\r", "\v"... as well.