Why is this not working?
bla="
multi
line
string
"
cat -A <<EOF
${bla//\$'\n'/\\\$'\n'}
EOF
this works:
cat -A <<EOF
$(cat <<<${bla//$'\n'/\\$'\n'})
EOF
as noted in a comment this also works:
newline=$'\n'
cat -A <<EOF
${bla//$newline/\\$newline}
EOF
Expected:
\$
multi\$
\$
line\$
\$
string\$
I guess it has something to do with Quoting and how heredocs work.
But as set -x is not working for parameter expansion debugging, i could not figue it out.
A link to where it is explained in the GNU Bash Reference Manual would also help.
Note: The $ in Expected: are from cat -A option and stand for the newline \n character.
I think you need to remove some of the
\in the parameter expansion.That is, it should read
${bla//$'\n'\$$'\n'}.What I have adds a
$at the end of each line.I am using