Challenge - 5 Problems
Here Document Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this here document script?
Consider the following Bash script using a here document. What will it print when run?
Bash Scripting
cat <<EOF Hello World EOF
Attempts:
2 left
💡 Hint
The here document sends the lines between <
✗ Incorrect
The cat command receives the lines 'Hello' and 'World' as input and prints them exactly, each on its own line.
💻 Command Output
intermediate2:00remaining
What happens if the delimiter is quoted in a here document?
What will this script output?
cat <<'EOF'
$HOME
EOF
Bash Scripting
cat <<'EOF'
$HOME
EOFAttempts:
2 left
💡 Hint
Quoting the delimiter disables variable expansion inside the here document.
✗ Incorrect
When the delimiter is quoted, the content is treated literally, so $HOME is not expanded.
🔧 Debug
advanced2:00remaining
Why does this here document script fail to run?
This script is intended to print a multi-line message, but it fails with a syntax error. Identify the cause.
cat <
Bash Scripting
cat <<EOF Hello World
Attempts:
2 left
💡 Hint
The shell expects the ending delimiter to close the here document.
✗ Incorrect
The here document must end with the exact delimiter on a line by itself. Missing it causes a syntax error.
🚀 Application
advanced2:00remaining
Which script correctly uses a here document to create a file with variable content?
You want to create a file named 'greeting.txt' containing the text 'Hello, Alice!'. The variable NAME='Alice' is set. Which script does this correctly?
Bash Scripting
NAME='Alice' # Choose the correct script
Attempts:
2 left
💡 Hint
Variable expansion happens only if the delimiter is unquoted.
✗ Incorrect
Option A expands $NAME to 'Alice'. Option A treats $NAME literally. Option A escapes the dollar sign, so no expansion. Option A prints 'NAME' literally.
🧠 Conceptual
expert2:00remaining
How does the shell treat leading tabs in here documents with <<-?
What is the effect of using <<-EOF instead of <
Bash Scripting
cat <<-EOF Hello World EOF
Attempts:
2 left
💡 Hint
The dash after << enables a special behavior with tabs.
✗ Incorrect
Using <<- allows the shell to ignore leading tab characters in the here document lines, making indentation cleaner.