Write a multiline template directly to cat standard input.
Keep $USER literal rather than expanding the variable.
Which here-document opening is appropriate?
Quoting a here-document delimiter suppresses parameter expansion and command substitution in the body, so fixed text is passed unchanged.
Detailed explanation
cat << EOFIncorrect. An unquoted delimiter allows $USER expansion in the body.
Incorrect. An unquoted delimiter allows $USER expansion in the body.
cat < EOFIncorrect. This redirects a file named EOF as input.
Incorrect. This redirects a file named EOF as input.
cat <<< EOFIncorrect. <<< is a here-string for one string, not a multiline here-document.
Incorrect. <<< is a here-string for one string, not a multiline here-document.
cat <<'EOF'Correct. cat <<'EOF' keeps the body literal until the closing delimiter.
Correct. cat <<'EOF' keeps the body literal until the closing delimiter.
Try it yourself
An example you can run in a temporary verification environment.
USER=alice; cat <<'EOF'
hello $USER
EOFExpected result
hello $USERKey points
- << begins a here-document
- A quoted delimiter suppresses expansion
- < reads a file
Notes
- Environment: Bash 5.x / here-documentのみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.