Operator [[ and Integers

Learn how to compare integers in the [[ operator.

Integer comparisons using the [[ operator

The [[ operator can compare integers. The table shows operations for doing that.

Operation Description Example
-eq The number on the left side equals the number on the right side [[ "$var" -eq 5 ]] && echo "The variable equals 5"
-ne The numbers are not equal [[ "$var" -ne 5 ]] && echo "The variable is not equal to 5"
-gt Greater (>) [[ "$var" -gt 5 ]] && echo "The variable is greater than 5"
-ge Greater or equal [[ "$var" -ge 5 ]] && echo "The variable is greater than or equal to 5"
-lt Less (<) [[ "$var" -lt 5 ]] && echo "The variable is less than 5"
-le Less or equal [[ "$var" -le 5 ]] && echo "The variable is less than or equal to 5"

Get hands-on with 1400+ tech skills courses.