0
0
Bash Scriptingscripting~5 mins

Here strings (<<<) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A>>
B<<
C<
D<<<
Which of these commands uses a here string correctly?
Acat <<< 'Hello World'
Bcat << 'Hello World'
Ccat < 'Hello World'
Dcat >> 'Hello World'
What will this command output? <br>grep 'test' <<< 'this is a test'
Athis is a test
Btest
CNo output
DError
Can here strings handle multi-line input?
AYes, multiple lines
BOnly if quoted
CNo, only single line
DOnly with special flags
Which is a benefit of using here strings?
ABetter for large files
BSimpler syntax for short input
CCreates temporary files
DRuns commands faster than normal
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.