cat << EOF > output.txt
Line 1
Line 2 with a $VARIABLE expanded
EOF
cat << 'EOF' > output.txt
This $VARIABLE won't be expanded
Neither will $(commands)
EOF
<<- strips leading tabs)if true; then
cat <<- EOF
This line's leading tab is stripped
EOF
fi
Only works with literal tab characters, not spaces.
grep "search" << EOF
line one
line two with search in it
EOF
read -r -d '' MY_VAR << 'EOF'
Multi-line
string content
EOF
| Syntax | Behavior |
|---|---|
<< EOF | Expand $vars and $(cmds) |
<< 'EOF' | No expansion (literal) |
<<- EOF | Strip leading tabs |
The delimiter (EOF) can be any word — END, HEREDOC, SQL, etc. — just match it exactly on the closing line (no leading/trailing spaces unless using <<- with tabs).