A here-document is a way to embed a block of text directly in a shell command or script and hand that text to a program as its standard input. Instead of putting the input in a separate file and redirecting from it, you write the input inline, bracketed by a starting marker and a matching ending marker. The classic form is “command <<EOF”, followed by lines of text, followed by a line containing only “EOF”. The word EOF is just a conventional delimiter; any unused word works. The shell reads everything up to that closing word and feeds it to the command as if it had come from a file.
The Bash manual specifies the mechanics precisely. The shell “reads input from the current source until it reads a line containing only the delimiter (with no trailing blanks)”, and the collected lines “then become the standard input for a command” (https://www.gnu.org/software/bash/manual/html_node/Redirections.html). A subtle but important detail is how the delimiter is written. If the opening word is left unquoted, the body is treated like a double-quoted string, so variables, command substitutions, and arithmetic are expanded inside it. If any part of the opening word is quoted, for example ”<<‘EOF’”, the body is taken literally with no expansion. That single choice decides whether your here-document interpolates values or passes its text through verbatim.
The manual also documents a useful variant, the ”<<-” operator, which strips leading tab characters from each input line and from the closing delimiter line. This exists so that a here-document embedded in a script can be indented to match the surrounding code, keeping the script readable, while the leading tabs are removed before the text reaches the command. It is a small ergonomic feature that makes here-documents far less ugly inside conditionals, loops, and function bodies.
A close relative is the here-string, written with ”<<<”. Where a here-document supplies many lines, a here-string supplies a single short string as standard input, as in “command <<< “some text"". It is the compact choice when you just want to pipe one value into a program that reads from standard input, avoiding the longer “echo text | command” idiom and the extra process that creates. Both forms are redirections, so they slot into the same place in a command line as input redirection from a file.
Here-documents are a staple of shell scripting because so many Unix tools are designed to read from standard input. They are how scripts feed multi-line SQL to a database client, send a canned message to mail, write out a configuration file with cat, or pass a small program to an interpreter, all without leaving temporary files lying around. By letting input live right next to the command that consumes it, the here-document keeps a script self-contained and readable, which is why it remains one of the most recognizable pieces of shell syntax.