Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - File Operations in Scripts
Identify the error in this script snippet:
while read line; do echo $line; done file.txt
AEcho command syntax is wrong
BIncorrect variable name used
CMissing input redirection operator < before file.txt
DMissing semicolon after read
Step-by-Step Solution
Solution:
  1. Step 1: Check how the file is provided to the loop

    The file must be redirected as input using < file.txt, not as an argument.
  2. Step 2: Confirm syntax correctness

    The rest of the syntax is correct; variable and echo usage are fine.
  3. Final Answer:

    Missing input redirection operator < before file.txt -> Option C
  4. Quick Check:

    Input redirection needed = D [OK]
Quick Trick: Use < file.txt to feed file lines, not argument [OK]
Common Mistakes:
MISTAKES
  • Passing filename as argument instead of redirecting input
  • Forgetting semicolon after read (optional here)
  • Misusing echo syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes