Bird
0
0

Find the bug in this command intended to read a file and print each line:

medium📝 Debug Q7 of 15
Linux CLI - Viewing and Editing Files
Find the bug in this command intended to read a file and print each line:
cat file.txt | while read line echo $line; done
AIncorrect pipe usage
BMissing 'do' keyword after while read line
CVariable 'line' not declared
DMissing input redirection
Step-by-Step Solution
Solution:
  1. Step 1: Review while loop syntax

    The 'do' keyword is required after 'while read line' to start the loop body.
  2. Step 2: Identify missing 'do'

    The command lacks 'do', causing syntax error.
  3. Final Answer:

    Missing 'do' keyword after while read line -> Option B
  4. Quick Check:

    Shell loops require 'do' keyword [OK]
Quick Trick: Always include 'do' after while condition [OK]
Common Mistakes:
MISTAKES
  • Omitting 'do' in loops
  • Misusing pipes with loops
  • Assuming variable declaration needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes