I'm used to use cat > /path/to/file << EOF when I, in a bash script, printed more than one line into a file... I was checking old code of my company and I found the cat EOT instruction instead of the cat EOF I'm used to (please notice the T instead of the F at the end of it) and curiosity bit me.
I did a quick research and I only found this other question, but I think it was not related to what I wanted to know.
I did some tests with the following code:
password=hello
cat > ./hello.txt << EOT
authentication {
auth_type PASS
auth_pass $password
}
EOT
And I get the exact same output as when I use EOF instead of EOT. The output is, as expected:
root@test_VM:~# bash test.sh && cat hello.txt
authentication {
auth_type PASS
auth_pass hello
}
So the questions are:
- What are the differences between the use of
EOTandEOF? - When should I use one over the other?
EOF– k.Cyborg Jun 08 '22 at 19:22AUTH_CONF_ENDor a similar label. – Kusalananda Jun 08 '22 at 19:24;,(,',#, then it has to be quoted, and then than means expansions are no longer performed inside. Even when quoted, using newline in the delimiter works in few shells (only dash and ksh93 in the few shells I tried). – Stéphane Chazelas Jun 08 '22 at 20:08:||:<<'# some comment'for instance to comment out some code up to# some commentfor instance. – Stéphane Chazelas Jun 08 '22 at 20:08:||? – ilkkachu Jun 08 '22 at 20:28EOFis generally used to indicate End Of File (https://en.wikipedia.org/wiki/End-of-file) and in this context the heredoc content is the "file".EOTis likely a reference to End Of Transmission (https://en.wikipedia.org/wiki/End-of-Transmission_character). Neither do anything special in this context compare toFOOorAUTH_CONF_ENDor even an intentionally confusingKEEP_GOING_DO_NOT_STOP_HERE, but there is a meaning or convention for the person reading/writing the code. – IBBoard Jun 09 '22 at 19:32