Instead of concatenation:
str=""
str+="This is a\n"
str+="multiline string"You can use a heredoc:
cat <<EOF
This is a
multiline string
EOFHowever, heredocs are meant for standard input. To store in a variable, you need a command that reads from standard input and assigns it.
That's what read does:
read -r -d '' str <<EOF
This is a
multiline string
EOFThe -r flag prevents backslash escapes from being interpreted, and the -d '' flag means read until EOF (empty delimiter).