Bird
0
0

Find the error in this Bash script:

medium📝 Debug Q14 of 15
Bash Scripting - Loops
Find the error in this Bash script:
for item apple banana cherry; do echo $item; done
AMissing semicolon after 'banana'
BVariable name 'item' is invalid
CIncorrect use of quotes around list items
DMissing 'in' keyword after 'for item'
Step-by-Step Solution
Solution:
  1. Step 1: Check for loop syntax

    Bash requires 'for variable in list; do ...; done'. The 'in' keyword is missing here.
  2. Step 2: Identify the error cause

    Without 'in', Bash cannot parse the list, causing a syntax error.
  3. Final Answer:

    Missing 'in' keyword after 'for item' -> Option D
  4. Quick Check:

    For loop needs 'in' keyword = B [OK]
Quick Trick: Always include 'in' after variable in for loops [OK]
Common Mistakes:
MISTAKES
  • Forgetting the 'in' keyword
  • Adding unnecessary semicolons inside list
  • Misnaming variables with invalid characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes