HEREDOC

Write to File

Append
cat << EOF >> /tmp/myfile.txt
Contents that are added to the file at the end
        You can indent files by spacing them appropriately
EOF

 

Noteworthy

  1. Make sure the last EOF (called the LimitString) is actually the very first item on the line. Do not indent, do not do anything other than make EOF begin at position #1.  If you wish to indent your LimitString, you can use <<- to disable leading tabs.
  2. If you do not want to interpret variables in the text, use single quotes around the first LimitString: cat << 'EOF' > /tmp/myfile.txt
  3. To write the heredoc to a file using sudo: cat << 'EOF' | sudo tee /etc/http.d/my_ssl_config