Challenge - 5 Problems
Integer Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Bash integer comparison?
Consider the following Bash script snippet. What will it print?
Bash Scripting
a=5 b=10 if [ $a -lt $b ]; then echo "a is less than b" else echo "a is not less than b" fi
Attempts:
2 left
💡 Hint
Remember that -lt means 'less than' in Bash integer comparisons.
✗ Incorrect
Since 5 is less than 10, the condition '[ $a -lt $b ]' is true, so the script prints 'a is less than b'.
💻 Command Output
intermediate2:00remaining
What output does this script produce with -ne operator?
What will this Bash script print?
Bash Scripting
x=7 y=7 if [ $x -ne $y ]; then echo "x and y are different" else echo "x and y are the same" fi
Attempts:
2 left
💡 Hint
The -ne operator means 'not equal'.
✗ Incorrect
Since x and y both equal 7, the condition '[ $x -ne $y ]' is false, so the else branch runs.
💻 Command Output
advanced2:00remaining
What is the output of this script using multiple integer comparisons?
What will this Bash script print?
Bash Scripting
num=15 if [ $num -ge 10 ] && [ $num -le 20 ]; then echo "num is between 10 and 20" else echo "num is outside the range" fi
Attempts:
2 left
💡 Hint
Check if num is greater or equal to 10 AND less or equal to 20.
✗ Incorrect
15 is between 10 and 20 inclusive, so both conditions are true and the script prints the first message.
💻 Command Output
advanced2:00remaining
What error does this script raise due to incorrect integer comparison?
What happens when you run this Bash script?
Bash Scripting
val=abc if [ $val -gt 5 ]; then echo "val is greater than 5" else echo "val is not greater than 5" fi
Attempts:
2 left
💡 Hint
The variable val contains non-numeric characters.
✗ Incorrect
Bash integer comparisons require numeric values. Using 'abc' causes an error about integer expression expected.
💻 Command Output
expert3:00remaining
What is the output of this complex integer comparison script?
Analyze the following Bash script and select the output it produces.
Bash Scripting
a=8 b=3 if [ $a -gt $b ]; then if [ $a -le 10 ]; then echo "a is greater than b and less or equal to 10" else echo "a is greater than b and greater than 10" fi else echo "a is not greater than b" fi
Attempts:
2 left
💡 Hint
Check both conditions carefully in the nested if statements.
✗ Incorrect
Since 8 > 3 and 8 <= 10, the first echo statement runs.