Bird
0
0

Which of the following is the correct syntax to check if variable x is greater than 10 in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - Conditionals
Which of the following is the correct syntax to check if variable x is greater than 10 in bash?
A[ $x > 10 ]
B[ $x -gt 10 ]
C[ $x -ge 10 ]
D[ $x => 10 ]
Step-by-Step Solution
Solution:
  1. Step 1: Recall integer comparison operators in bash

    For greater than, bash uses -gt inside [ ]. The symbol > is for string comparison or redirection.
  2. Step 2: Check each option

    [ $x -gt 10 ] uses [ $x -gt 10 ] which is correct syntax for integer greater than check.
  3. Final Answer:

    [ $x -gt 10 ] -> Option B
  4. Quick Check:

    Greater than check uses -gt [OK]
Quick Trick: Use -gt for greater than, not > inside [ ] [OK]
Common Mistakes:
MISTAKES
  • Using > instead of -gt inside [ ]
  • Using => instead of -ge
  • Missing spaces around brackets and operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes