Recall & Review
beginner
What does the
-eq operator do in bash scripting?The
-eq operator checks if two integers are equal. It returns true if they are the same number.Click to reveal answer
beginner
How do you check if two numbers are not equal in bash?
Use the
-ne operator. It returns true if the two integers are different.Click to reveal answer
intermediate
What is the difference between
-gt and -ge in bash?-gt means 'greater than' (strictly bigger), while -ge means 'greater than or equal to' (bigger or the same).Click to reveal answer
beginner
Write a bash condition to check if variable
x is less than 10.You can write:
if [ "$x" -lt 10 ]; then to check if x is less than 10.Click to reveal answer
intermediate
Why should you use integer comparison operators instead of string comparison for numbers in bash?
Integer operators correctly compare numeric values, while string comparison compares characters and can give wrong results for numbers.
Click to reveal answer
Which operator checks if two integers are equal in bash?
✗ Incorrect
The
-eq operator tests if two integers are equal.What does the
-ne operator do?✗ Incorrect
-ne means 'not equal' for integer comparison.Which operator means 'greater than or equal to'?
✗ Incorrect
-ge means 'greater than or equal to'.How would you check if variable
num is less than 5?✗ Incorrect
Use
-lt to check if a number is less than another.Why avoid using string comparison operators for numbers in bash?
✗ Incorrect
String comparison compares characters, which can give wrong results for numbers.
Explain how to compare two integers in bash using the operators -eq, -ne, -gt, -lt, -ge, and -le.
Think about how you check if numbers are equal, not equal, bigger, or smaller.
You got /4 concepts.
Describe why integer comparison operators are important in bash scripting and give an example where string comparison would fail.
Consider how numbers behave differently as strings.
You got /4 concepts.