here-禁用shell解析的文档

Eth*_*ker 3 bash heredoc

我需要一个here文件上传TeX到在线shell.我不希望shell对内容做任何事情.以下MWE是我迄今为止管理得最好的.

cat << EOF > /tmp/mytex 
\documentclass{article}
\begin{document}
Test mathematics:  $ 2^{10} = 1024$ works but
$e^{i\pi} = -1$ is mangled because no space follows the $e$.
"double" and 'single' quotes should be preserved too.
\end{document}
EOF
Run Code Online (Sandbox Code Playgroud)

per*_*eal 8

试试这个:

cat << 'EOF' > /tmp/mytex 
\documentclass{article}
\begin{document}
Test mathematics:  $ 2^{10} = 1024$ works but
$e^{i\pi} = -1$ is mangled because no space follows the $e$.
"double" and 'single' quotes should be preserved too.
\end{document}
EOF
Run Code Online (Sandbox Code Playgroud)

从bash参考手册:

here-documents的格式是:

<<[-]word
         here-document 
delimiter 
Run Code Online (Sandbox Code Playgroud)

如果引用单词中的任何字符,则分隔符是单词上的引号删除的结果,并且不会展开here-document中的行.