Recall & Review
beginner
What is a here string (<<<) in bash scripting?
A here string is a way to pass a short string as input to a command directly, using <<< followed by the string. It acts like a small input file.
Click to reveal answer
intermediate
How does a here string differ from a here document in bash?
A here string passes a single string as input, while a here document passes multiple lines or a block of text. Here strings use <<< and here documents use <<.
Click to reveal answer
beginner
Example: What does this command do? <br>
grep 'hello' <<< 'hello world'It searches for the word 'hello' in the string 'hello world' passed as input via the here string. It will output 'hello world' because 'hello' is found.
Click to reveal answer
beginner
Can you use variables with here strings? Show an example.
Yes. For example: <br>
name='Alice'<br>grep 'Alice' <<< "$name" <br>This passes the value of the variable 'name' as input.Click to reveal answer
intermediate
Why might you choose a here string over echo piping?
Here strings are simpler and faster for short input because they avoid creating a pipe. They are cleaner for passing small strings directly to commands.
Click to reveal answer
What symbol is used to create a here string in bash?
✗ Incorrect
The here string uses the symbol <<< to pass a string as input.
Which of these commands uses a here string correctly?
✗ Incorrect
cat <<< 'Hello World' uses a here string to pass 'Hello World' as input.
What will this command output? <br>grep 'test' <<< 'this is a test'
✗ Incorrect
The grep finds 'test' in the input string and outputs the whole line.
Can here strings handle multi-line input?
✗ Incorrect
Here strings pass a single string, usually one line. For multiple lines, use here documents.
Which is a benefit of using here strings?
✗ Incorrect
Here strings provide a simple way to pass short input strings directly.
Explain what a here string (<<<) is and how it is used in bash scripting.
Think about how you give a command a quick input string without a file.
You got /4 concepts.
Describe a practical example where a here string is useful and why it might be preferred over echo piping.
Consider searching text or feeding a small string to a command.
You got /4 concepts.