Bird
0
0

Which of the following is the correct way to use a here string to pass the text example to the grep command?

easy📝 Syntax Q3 of 15
Bash Scripting - Text Processing in Scripts
Which of the following is the correct way to use a here string to pass the text example to the grep command?
Agrep 'ex' <<< example
Bgrep 'ex' <<< "example"
Cgrep 'ex' << example
Dgrep 'ex' < example
Step-by-Step Solution
Solution:
  1. Step 1: Recognize here string syntax

    The here string operator requires the string to be quoted or properly formatted to be passed as input.
  2. Step 2: Analyze options

    grep 'ex' <<< "example" correctly uses quotes around the string with <<<. grep 'ex' <<< example lacks quotes, which can cause errors if the string contains spaces or special characters. Options C and D use incorrect redirection operators.
  3. Final Answer:

    grep 'ex' <<< "example" -> Option B
  4. Quick Check:

    Here string with quoted string input [OK]
Quick Trick: Quote strings when using here strings to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Not quoting the string after <<<
  • Using << instead of <<<
  • Using input redirection < instead of here string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes