Search code examples
linuxbashshellshash

How can I add a new line in a Bash string?


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?


Solution

  • $ echo "a\nb"
    a\nb
    $ echo -e "a\nb"
    a
    b