0
0
Bash Scriptingscripting~20 mins

Here strings (<<<) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Here String Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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"
Aread: command not found
Bline
CHello World
DHello
Attempts:
2 left
💡 Hint
The here string sends the string as input to the read command.
💻 Command Output
intermediate
2: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"
Aone two three
Bone
C
one two
three
D
one
two
three
Attempts:
2 left
💡 Hint
The here string sends the entire string as a single line to the loop.
📝 Syntax
advanced
2: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?
Awc -w < "apple banana cherry"
Bwc -w <<< "apple banana cherry"
Cwc -w << "apple banana cherry"
Dwc -w <<< apple banana cherry
Attempts:
2 left
💡 Hint
Here strings use <<< followed by a quoted string.
🔧 Debug
advanced
2: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"
AThe read command does not output anything, so var is empty
BSyntax error: missing quotes around read
Cread command cannot be used with here strings
DThe variable 'line' is not declared
Attempts:
2 left
💡 Hint
The read command reads input but does not print it.
🚀 Application
expert
2: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?
A
grep 'pattern' &lt;&lt;&lt; line1
line2
line3
B
grep 'pattern' &lt;&lt;&lt; "line1
line2
line3"
C
grep 'pattern' &lt;&lt;&lt; 'line1
line2
line3'
Dgrep 'pattern' <<< $'line1\nline2\nline3'
Attempts:
2 left
💡 Hint
Use $'...' to interpret escape sequences inside a here string.