Bash 5 reference · Shell Builtins and Syntax

here-document (Bash syntax)

Feed multiple lines to a command with <<EOF; quote the marker to stop variable expansion, use <<- to strip tabs.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

cmd <<EOF ... EOF   cmd <<'EOF' ... EOF   cmd <<< 'string'

Parameters

ParameterDescription
<<EOF Variables and $(...) are expanded.
<<'EOF' Literal: nothing expanded.
<<< Here-string: one string as input.

Examples

Expanding here-document
name=api
cat <<EOF
service: $name
literal: \$name
EOF

Output

service: api
literal: $name

Run this on your computer — see “Get Started” for setup.

Quoted marker and here-string
cat <<'EOF' > script.sh
echo "$HOME stays literal"
EOF
cat script.sh
tr a-z A-Z <<< 'here-string'

Output

echo "$HOME stays literal"
HERE-STRING

Run this on your computer — see “Get Started” for setup.

Was this page helpful?