Heredocs, Herestrings & Process Substitution in Bash

From the Bash Scripting cheat sheet · Here-docs & Process Substitution · verified Jul 2026

Heredocs, Herestrings & Process Substitution

Feed blocks of text and command output.

bash
# Quick Reference
cat <<EOF
multi-line
text with $var expanded
EOF

grep foo <<< "$string"          # here-string
diff <(sort a) <(sort b)        # process substitution
💡 <<EOF expands $vars inside; <<'EOF' (quoted delimiter) keeps everything literal.
⚡ <<< "$str" (here-string) is a quick way to pipe one string into a command's stdin.
📌 <(cmd) turns command output into a temp file path - great for diff <(a) <(b).
🟢 <<-EOF strips leading tabs (only tabs, not spaces) so you can indent the block.
heredocprocess-substitution
Back to the full Bash Scripting cheat sheet