0
0
Bash Scriptingscripting~10 mins

Here documents (<<EOF) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a here document that outputs "Hello World".

Bash Scripting
cat <<[1]
Hello World
EOF
Drag options to blanks, or click blank then click option'
AEOF
BEND
CSTOP
DDONE
Attempts:
3 left
💡 Hint
Common Mistakes
Using different words after << and at the end.
Forgetting to put the ending delimiter.
2fill in blank
medium

Complete the code to assign a multi-line string to a variable using a here document.

Bash Scripting
myvar=$(cat <<[1]
Line 1
Line 2
EOF
)
Drag options to blanks, or click blank then click option'
ASTOP
BEOF
CEND
DDONE
Attempts:
3 left
💡 Hint
Common Mistakes
Using different delimiters at start and end.
Not using command substitution to assign the string.
3fill in blank
hard

Fix the error in the here document that should print a variable's value.

Bash Scripting
name="Alice"
echo <<[1]
Hello $name
EOF
Drag options to blanks, or click blank then click option'
AEOF
B"EOF"
C-EOF
D'EOF'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around EOF which disables variable expansion.
Not using <<- when indenting the delimiter.
4fill in blank
hard

Fill both blanks to create a here document that does NOT expand variables.

Bash Scripting
cat <<[1]
The value is $value
[2]
Drag options to blanks, or click blank then click option'
A'EOF'
BEOF
C"EOF"
D-EOF
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted EOF which expands variables.
Mixing quoted and unquoted delimiters.
5fill in blank
hard

Fill all three blanks to create a here document that strips leading tabs and expands variables.

Bash Scripting
cat <<[1]
	Line 1
	Value: $[2]
[3]
Drag options to blanks, or click blank then click option'
AEOF
Bname
C-EOF
D'EOF'
Attempts:
3 left
💡 Hint
Common Mistakes
Quoting EOF which disables variable expansion.
Using wrong variable name inside the here document.