Glossary

Here Document

Also known as: heredoc, here document

A here document (or heredoc) is a shell syntax for providing multi-line input to a command inline, without needing a separate file. You mark the start with << followed by a delimiter, and everything up to a line containing only that delimiter becomes the command's stdin.

cat <<EOF > config.yml
name: myapp
version: 1.0
EOF

Variable expansion happens inside a plain heredoc, so $HOME would be expanded. To suppress expansion—useful when the content contains literal $ signs—quote the delimiter:

ssh host 'bash -s' <<'EOF'
echo "$USER on $(hostname)"      # expanded on the remote side
EOF

Prefixing the operator with a dash (<<-EOF) strips leading tabs from each line, letting you indent the body for readability without affecting the content the command receives. This is invaluable for keeping scripts tidy.

Heredocs are heavily used for writing out configuration files from installers, sending SQL to mysql or psql in scripts, and passing remote scripts to ssh. A related construct, the here string (<<<), provides a single line of stdin inline and is more limited but syntactically lighter.

Related terms: Redirection, Shell

Discussed in:

Also defined in: Textbook of Linux