Bird
0
0

Identify the error in this Bash script:

medium📝 Debug Q6 of 15
Bash Scripting - Loops
Identify the error in this Bash script:
for fruit in apple banana cherry
  echo $fruit
end
AVariable 'fruit' is not declared
BMissing semicolon after 'banana'
CThe loop should end with 'done' instead of 'end'
DQuotes are required around list items
Step-by-Step Solution
Solution:
  1. Step 1: Check loop syntax

    Bash for loops start with 'for ... in ...' and end with 'done'.
  2. Step 2: Identify error

    The script incorrectly uses 'end' instead of 'done'.
  3. Final Answer:

    The loop should end with 'done' instead of 'end' -> Option C
  4. Quick Check:

    Loops in Bash always end with 'done' [OK]
Quick Trick: Bash loops end with 'done', not 'end' [OK]
Common Mistakes:
MISTAKES
  • Using 'end' instead of 'done'
  • Forgetting to close the loop
  • Misplacing semicolons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes