17.4. Testing numbers

To test for numbers a different sort of operators are at our disposal. The general format is:

"number" numeric_operator "number" 

or

[ "number" numeric_operator "number" ] 

where the numeric_operator can be:

-eq The two numbers are equal
-ne The two numbers are not equal
-gt The first number is greater than the second number
-lt The first number is less than the second number
-le The first number is less than or equal to the second number
-gt The first number is greater than or equal to the second number

Both the following examples returns the same result. To test if a number is equal to another number (in this case is 130 equal to 130):

						$ NUMBER=130 
$ [ "$NUMBER" -eq "130" ] 
$ echo $? 
0
					

Phew! I’m glad that one returned ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.