Write Multi-Line Files With Here-Documents

Embed configuration or scripts inline using <<'EOF' blocks.

macOSbashshellscriptingLow risk
Use cat <<'EOF' > file ... EOF to write a literal multi-line block to a file.

01Command

Command
$ cat <<'EOF' > config.ini
[app]
name=cmdcv
EOF

02What it does

A here-document feeds everything up to the delimiter as standard input, which keeps configuration or generated scripts readable inside a shell script. Quoting the delimiter disables variable expansion, so content is written literally. Editing many files by hand in a GUI does not scale like this does.

03Risk

RiskLow risk
RequirementsmacOS default zsh/bash (bash 3.2+; some features need bash 4+ via Homebrew)
CompatibilitymacOS with bash 3.2+ (GNU bash 4+ via Homebrew for advanced features)
!Warning: An indented delimiter will not close the block; use <<- only with tabs, or keep the delimiter at column zero.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer