Is there any way to for a Bash heredoc to interpret \'\\n\\\' in a heredoc?
I have an iteratively built string in a loop, something like
for i in wor
As others (and other answers to other questions) have said, you can put encoded characters into a string for the shell to interpret.
x=$'\n' # newline
printf -v x '\n' # newline
That said, I don't believe there is any way to directly put an encoded newline into a heredoc.
cat <
just outputs a literal \n
cat <<$'EOF'
…
EOF
is nothing special, nor is <<'EOF'
The best you can do is to preencode the newline, and include the expansion in the heredoc:
nl=$'\n'
cat <
outputs
foo bar
baz