Bird
0
0

What is the issue with this Bash script snippet?

medium📝 Debug Q6 of 15
Linux CLI - Linux Basics and Terminal
What is the issue with this Bash script snippet?
if [ $num -gt 10 ]
echo "Number is greater than 10"
fi
AThe 'fi' keyword should be replaced with 'end'
BThe variable $num should be quoted as "$num"
CThe 'then' keyword is missing after the if condition
DThe comparison operator '-gt' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Identify the if statement syntax

    In Bash, an if statement requires the 'then' keyword after the condition.
  2. Step 2: Check the script snippet

    The snippet lacks 'then' after '[ $num -gt 10 ]', which causes a syntax error.
  3. Final Answer:

    The 'then' keyword is missing after the if condition -> Option C
  4. Quick Check:

    Missing 'then' in if statement [OK]
Quick Trick: Always include 'then' after if condition [OK]
Common Mistakes:
  • Forgetting the 'then' keyword in if statements
  • Using 'end' instead of 'fi' to close if blocks
  • Not quoting variables in test conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes