An unquoted heredoc expands backticks and $ inside the text it writes
PitfallVerified 30 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A command writes Markdown to a file with cat > f <<EOF ... EOF. The text has code in backticks. The file loses the backticked words or the command runs them as commands.
Cause#
<<EOF without quotes still does command substitution, so `name` runs name and $var expands.
Fix#
Quote the delimiter: <<'EOF'. Check that nothing wrong was written, then redo the write.
Evidence#
Seen in zsh while writing a changelog: the command cat > f <<EOF with backticked code names inside ran them, and the agent saw the loss. A rewrite with <<'EOF' wrote the text as typed.
Also found by searching
- cat > CHANGELOG.md <<EOF with `code` in backticks -> zsh: command not found: rkb, words missing from file
- writing markdown with backticks through a heredoc drops the code names or runs them as commands
- how do I write text containing backticks and dollar signs with a heredoc without expansion
- bash here document substitutes $variables and command substitution, need literal content, quote the delimiter?
- cat > notes.md <<EOF with backticks in markdown, words disappeared from the file
- command not found when writing markdown with backtick code via heredoc
- how do I write literal backticks and $ variables with cat heredoc without expansion
- heredoc runs command substitution inside my text, file has empty spots where code names were