Bird
0
0

Find the error in this script:

medium📝 Debug Q7 of 15
Bash Scripting - Loops
Find the error in this script:
i=0
while [ $i -lt 5 ]
do
  i=$((i+1))
  if [ $i -eq 3 ]; then
    break
  fi
  echo $i
done
AMissing done keyword
BMissing semicolon or newline after while condition
CIncorrect arithmetic syntax
DNo error, script runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check while loop syntax

    The while condition must end with a semicolon or newline before do.
  2. Step 2: Identify missing syntax

    Here, while [ $i -lt 5 ] is not followed by a semicolon or newline before do, causing syntax error.
  3. Final Answer:

    Missing semicolon or newline after while condition -> Option B
  4. Quick Check:

    while needs semicolon/newline before do = D [OK]
Quick Trick: Put semicolon or newline after while condition before do [OK]
Common Mistakes:
MISTAKES
  • Omitting semicolon after while condition
  • Forgetting done keyword (not the case here)
  • Incorrect arithmetic syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes