Here-documents let a Bash script pass a readable block of text to a command's standard input without keeping that text in a separate input file. They fit short generated messages, configuration fragments, SQL batches, and templates that belong next to the script logic.
The «WORD redirection starts the block, and a later line containing only WORD ends it. Bash does not expand the delimiter word itself; quoting any part of that word turns off expansion inside the here-document body.
Use an unquoted delimiter when the body should expand variables, command substitutions, or arithmetic expressions. Use a quoted delimiter when the body is a literal template, and keep the closing delimiter alone on its line with no indentation or trailing blanks unless «- is deliberately using tab indentation.
Related: script setup with How to create and run a Bash script
variable expansion with How to use variables in Bash scripts
command substitution inside unquoted here-documents with How to use command substitution in Bash
#!/usr/bin/env bash set -euo pipefail recipient=${1:-operations} cat <<MESSAGE To: $recipient Status: ready MESSAGE cat <<'LITERAL' Literal example: $recipient LITERAL
The delimiter names MESSAGE and LITERAL are only markers. Choose words that do not appear by themselves inside the block.
$ bash -n message.sh
No output means Bash parsed the here-document delimiters and the rest of the script without a syntax error.
$ bash message.sh To: operations Status: ready Literal example: $recipient
cat <<MESSAGE To: $recipient Status: ready MESSAGE
cat <<'LITERAL' Literal example: $recipient LITERAL
Bash strips leading tabs with «-, but it does not strip spaces. Use plain « when the indentation might be spaces.