Numeric Comparisons

Numeric Comparisons

The most common test evaluation methods perform a comparison of two numerical values.

n1 -eq n2 Checks if n1 is equal to n2
if [ $n1 -eq $n2 ]
then
do_something
fi
n1 -ge n2 Checks if n1 is greater than or equal to n2
if [ $n1 -ge $n2 ]
then
do_something
fi
n1 -gt n2 Checks if n1 is greater than n2
if [ $n1 -gt $n2 ]
then
do_something
fi
n1 -le n2 Checks if n1 less than or equal to n2
if [ $n1 -le $n2 ]
then
do_something
fi
n1 -lt n2 Checks if n1 is less than n2
if [ $n1 -lt $n2 ]
then
do_something
fi
n1 -ne n2 Checks if n1 is not equal to n2
if [ $n1 -ne $n2 ]
then
do_something
fi