What Is a Here-Document? Inline Multi-Line Input
A here-document is a shell feature that feeds a block of inline, multi-line text to a command as its standard input, using the << delimiter.
When you need to pass several lines of text to a command, typing them one echo at a time is awkward. A here-document lets you embed a whole block of text right in the script and pipe it into a command as stdin. CI scripts use here-docs to write config files, feed SQL to a database, or build multi-line messages.
What a here-document is
A here-doc starts with << followed by a delimiter word, then lines of text, and ends when that delimiter appears alone on a line. All the lines in between are sent as stdin to the command.
A basic example
Writing cat <<EOF > config.txt then several lines then EOF creates a file with exactly those lines. The text between the markers becomes the input to cat, which writes it out.
Expansion and quoting
- By default, variables and command substitutions inside a here-doc are expanded.
- Quoting the delimiter, like
<<'EOF', disables expansion so the text is literal. - Use
<<-EOFto strip leading tabs for cleaner indentation.
Here-doc versus here-string
A here-document supplies multiple lines; a here-string, written <<<, supplies a single string. Both feed stdin without a separate file, but here-docs are for blocks of text.
Here-documents in CI
CI scripts use here-docs to generate config files inline or run multi-statement SQL against a service. Watch the quoting: an unquoted delimiter will expand $ references, which can break templates or leak secrets into a file.
Generating files on managed runners
On Latchkey runners, a here-doc is a tidy way to write a config or script during a step without checking it into the repo. Quote the delimiter when the content should stay literal, especially if it contains secret placeholders.
Key takeaways
- A here-document feeds a block of inline text to a command as stdin.
- It starts with
<<DELIMand ends when DELIM appears alone on a line. - Quoting the delimiter disables variable expansion for literal content.