Bird
0
0

Find the error in this script snippet:

medium📝 Debug Q7 of 15
Bash Scripting - Loops
Find the error in this script snippet:
for file in *; do if [ -f $file ]; then echo $file; fi
AIncorrect test operator '-f'
BMissing quotes around $file in test
CMissing 'then' keyword in if statement
DMissing 'done' keyword to close the loop
Step-by-Step Solution
Solution:
  1. Step 1: Check loop structure

    The 'for' loop must end with 'done' keyword to close it properly.
  2. Step 2: Verify script completeness

    The script ends after 'fi' without 'done', causing syntax error.
  3. Final Answer:

    Missing 'done' keyword to close the loop -> Option D
  4. Quick Check:

    Loops must end with 'done' = A [OK]
Quick Trick: Always close loops with 'done' keyword [OK]
Common Mistakes:
MISTAKES
  • Forgetting 'done' at loop end
  • Not quoting variables in tests
  • Misplacing 'then' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes