bash - 禁用 shell 解析的 here-document

标签 bash heredoc

我需要一个用于将 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

最佳答案

试试这个:

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

From the bash reference manual :

The format of here-documents is:

<<[-]word
         here-document 
delimiter 

If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded.

关于bash - 禁用 shell 解析的 here-document,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15329323/

相关文章:

mysql - 从linux终端插入mysql

macos - 在 mac osx 终端应用程序中扩展 ascii 字符和 ansi

linux - 计算使用 find 命令找到的行数

php - 如何确保进出数据库的所有数据都是 utf-8 编码的?

linux - 如何转义作为 shell 脚本中命令的关键字?

PHP 文档语法

Bash 在循环中检测到错误然后继续处理

java - 在 Java 中构造 HTML 字符串的简单/直接/Heredoc 方式

linux - Bash 尝试执行 heredoc 中的命令

php - 是否可以在 heredoc 中使用 php 函数?