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?

Upvotes: 36

Views: 87695

Answers (1)

Adam Siemion
Adam Siemion

Reputation: 16039

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

Upvotes: 78

Related Questions