Bird
0
0

Identify the error in this script:

medium📝 Debug Q6 of 15
Bash Scripting - Loops
Identify the error in this script:
for i in 1 2 3; do
  if [ $i -eq 2 ]
    continue
  fi
  echo $i
done
AMissing semicolon or newline before continue
BIncorrect use of break instead of continue
CEcho command is outside the loop
DLoop variable is not declared
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

    The if statement requires a semicolon or newline before the command inside it.
  2. Step 2: Identify missing syntax

    Here, continue is on the next line without a semicolon or newline after the condition, causing syntax error.
  3. Final Answer:

    Missing semicolon or newline before continue -> Option A
  4. Quick Check:

    if syntax needs semicolon/newline = A [OK]
Quick Trick: Put semicolon or newline before commands in if [ ] [OK]
Common Mistakes:
MISTAKES
  • Omitting semicolon after if condition
  • Placing continue outside if block
  • Misusing break instead of continue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes