VAR=$(cat <<'END_HEREDOC' abc'asdf" $(dont-execute-this) foo"bar"'' END_HEREDOC ) # this will echo variable with new lines intact echo "$VAR" # this will echo variable without new lines (changed to space character) echo $VAR