35

The new line \n is not taken account in the shell strings:

str="aaa\nbbbb"
echo $str

Output:

aaa\nbbbb

Expected result:

aaa
bbbb

How can I add a new line in the string?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
developer
  • 4,400
  • 5
  • 37
  • 55
  • linuxcdeveloper: always try to use echo -e "your display part" it makes the right effect( -e : enable interpretation of backslash escapes ) – Ranjithkumar T Dec 17 '13 at 06:33

1 Answers1

75
$ echo "a\nb"
a\nb
$ echo -e "a\nb"
a
b
Adam Siemion
  • 15,064
  • 6
  • 51
  • 88