This
STR=\"Hello\\nWorld\" echo $STR
produces as output
Hello\\nWorld
instead of
Hello Wo
I wasn't really happy with any of the options here. This is what worked for me.
str=$(printf "%s" "first line") str=$(printf "$str\n%s" "another line") str=$(printf "$str\n%s" "and another line")