有没有办法让Bash heredoc在heredoc中解释'\n \'?
我在循环中有一个迭代构建的字符串,类似于
for i in word1 word2 word3
do
TMP_VAR=$i
ret="$ret\n$TMP_VAR"
done
Run Code Online (Sandbox Code Playgroud)
然后我想在heredoc中使用创建的字符串:
cat <<EOF > myfile
HEADER
==
$ret
==
TRAILER
EOF
Run Code Online (Sandbox Code Playgroud)
但是我想将"\n"字符解释为换行符,以便输出为
HEADER
==
word1
word2
word3
==
TRAILER
Run Code Online (Sandbox Code Playgroud)
代替
HEADER
==
\nword1\nword2\nword3
==
TRAILER
Run Code Online (Sandbox Code Playgroud)
可能吗?或者我应该以某种方式构建我的初始字符串?