Search notes:

Bash: here document

Creating a file

Combining cat with a here document allows to create a file:
cat > /tmp/tq84.file << EOF
Lorem ipsum dolor sit amet, consectetur
adipiscing elit.
EOF
Github repository about-Bash, path: /scripts/here-document/cat-to-file

Reading lines from a here document

Similarly, lines can be read with read and a while loop to iterate over the lines of a here document:
#!/bin/bash
while read line; do
  echo "line = $line"
done << EOF
first line
second line
third line
EOF
Github repository about-Bash, path: /scripts/here-document/while-read

Suppress leading tabulators

If the limit string starts with a hyphen, leading tabulators are suppressed.
Thus, it is possible to create here document with that look nicer.
#!/bin/bash

cat <<-EOF
  All lines in this here document
  start with spaces.
  
  The dash in front of the EOF
  does not remove them.
EOF

echo -e "\n---------------\n"

cat <<-EOF
	The lines in this here document
	start with a tabulator.
	
	The dash in front of the EOF
	removes them.
EOF
Github repository about-Bash, path: /scripts/here-document/suppress-leading-tabs

See also

bash
A here string is similar to a here document.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Linux/sh...', 1740451403, '3.23.92.85', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Linux/shell/bash/scripts/here-document(95): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78