Bird
0
0

What is wrong with this script snippet?

medium📝 Debug Q7 of 15
Linux CLI - Linux Basics and Terminal
What is wrong with this script snippet?
if [ $value -eq 10 ]
then
 echo "Value is 10"
fi
AMissing semicolon or newline before then
BMissing space after [ and before ]
CIncorrect use of -eq for string comparison
DNo error, script runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

    In Bash, the then keyword must be on a new line or after a semicolon following the condition. Here, the newline after the condition satisfies this.
  2. Step 2: Identify if there's an issue

    The snippet has a newline after [ $value -eq 10 ] before then, so it's valid syntax with no error.
  3. Final Answer:

    No error, script runs correctly -> Option D
  4. Quick Check:

    If statement syntax requires semicolon or newline before then = newline present [OK]
Quick Trick: Put semicolon or newline before then in if statements [OK]
Common Mistakes:
  • No space before then
  • Using -eq for strings incorrectly
  • Missing spaces inside brackets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes