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.

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.

  1. Remove newline character from the end of a string in Perl
  2. xargs when the filename contains a newline
  3. Cross platform newline in PHP
  4. Wide character in print… warning in Perl
  5. How to echo a tab in bash?

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>