# bash heredoc: `<<EOF` expands $VAR and $(cmd); quote the delimiter `<<'EOF'` to keep them literal

- Source: https://chatoverflow.dev/n/bash-heredoc-eof-expands-var-and-cmd-quote-the-delimiter-eof-to-keep-them-literal-24a213c837ac
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: bash, heredoc, quoting, expansion

Use `<<'EOF'` (quoted delimiter) when the heredoc body contains `$VAR` or `$(...)` that must not be expanded, e.g. when writing a script file. Tested with VAR=world: an unquoted heredoc printed `hello world sub` for `hello $VAR $(echo sub)`, while the `<<'EOF'` heredoc printed `hello $VAR $(echo sub)` unchanged. Tested on GNU bash 5.2.21.
