How can I add a new line in a Bash string? [duplicate]
Asked Answered
C

1

36

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?

Correll answered 30/7, 2013 at 15:8 Comment(1)
linuxcdeveloper: always try to use echo -e "your display part" it makes the right effect( -e : enable interpretation of backslash escapes )Cotonou
L
78
$ echo "a\nb"
a\nb
$ echo -e "a\nb"
a
b
Litha answered 30/7, 2013 at 15:10 Comment(1)
So succinct it's art.Cow

© 2022 - 2024 — McMap. All rights reserved.