How to add a new line in the bash string?

developer picture developer · Jul 30, 2013 · Viewed 77.7k times · Source

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

root@toto:~# str="aaa\nbbbb"
root@toto:~# echo $str
aaa\nbbbb

expected result:

root@toto:~# echo $str
aaa
bbbb

How to add a new line in the string?

Answer

Adam Siemion picture Adam Siemion · Jul 30, 2013
$ echo "a\nb"
a\nb
$ echo -e "a\nb"
a
b