Bird
0
0

Identify the mistake in this bash script snippet:

medium📝 Debug Q6 of 15
Bash Scripting - Conditionals
Identify the mistake in this bash script snippet:
#!/bin/bash
count=3
if [ $count -gt 2 ]
  echo "Greater"
fi
AMissing 'fi' to close the if block
BIncorrect use of square brackets
CVariable 'count' is not initialized
DMissing 'then' keyword after the if condition
Step-by-Step Solution
Solution:
  1. Step 1: Review if statement syntax

    In bash, the 'then' keyword must follow the condition in an if statement.
  2. Step 2: Check the script

    The script lacks 'then' after the condition '[ $count -gt 2 ]'.
  3. Final Answer:

    Missing 'then' keyword after the if condition -> Option D
  4. Quick Check:

    Ensure 'then' is present after if condition [OK]
Quick Trick: Always include 'then' after if condition [OK]
Common Mistakes:
MISTAKES
  • Omitting 'then' after the if condition
  • Forgetting to close the if block with 'fi'
  • Incorrect spacing inside [ ]
  • Using wrong comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes