Challenge - 5 Problems
Here String 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 Bash script using here string?
Consider the following Bash script snippet. What will it print when executed?
Bash Scripting
read line <<< "Hello World" echo "$line"
Attempts:
2 left
💡 Hint
The here string sends the string as input to the read command.
✗ Incorrect
The read command reads the string "Hello World" from the here string and stores it in the variable 'line'. Then echo prints the full string.
💻 Command Output
intermediate2:00remaining
What does this script output when using here string with a loop?
What will be printed by this Bash script?
Bash Scripting
while read word; do echo "$word" done <<< "one two three"
Attempts:
2 left
💡 Hint
The here string sends the entire string as a single line to the loop.
✗ Incorrect
The here string sends the whole string as one line, so the loop reads it once and prints it once.
📝 Syntax
advanced2:00remaining
Which option correctly uses a here string to count words?
Which of the following Bash commands correctly counts the number of words in the string "apple banana cherry" using a here string?
Attempts:
2 left
💡 Hint
Here strings use <<< followed by a quoted string.
✗ Incorrect
Option B correctly uses <<< with a quoted string to send input to wc. Option B uses incorrect syntax for here document. Option B tries to redirect a file named "apple banana cherry". Option B misses quotes causing syntax error.
🔧 Debug
advanced2:00remaining
Why does this script fail to assign the variable correctly?
What is the error in this Bash script and why does it not assign the variable 'var' as expected?
var=$(read line <<< "test")
echo "$var"
Attempts:
2 left
💡 Hint
The read command reads input but does not print it.
✗ Incorrect
The read command reads input into 'line' but does not output it. Using command substitution captures output, so var is empty.
🚀 Application
expert2:00remaining
How to use here string to pass multiple lines to a command?
You want to pass multiple lines of text to a command using a here string. Which option correctly does this in Bash?
Attempts:
2 left
💡 Hint
Use $'...' to interpret escape sequences inside a here string.
✗ Incorrect
Option D uses $'...' syntax to interpret \n as newlines, passing multiple lines correctly. Option D passes literal \n characters, not newlines. Option D passes literal backslash and n characters. Option D is invalid syntax.