Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

here-document that disables shell parsing

Tags:

bash

heredoc

I need a here document for uploading TeX to an online shell. I don't want the shell to do anything with the contents. The following MWE is the best I have managed so far.

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
like image 654
Ethan Bolker Avatar asked Apr 11 '26 09:04

Ethan Bolker


1 Answers

Try this:

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.

like image 160
perreal Avatar answered Apr 13 '26 15:04

perreal