Numerical comparison operators for the test command

The following is the summary of various options for numerical comparison using test:

Test Operator

Tests True If

[ integer_1 -eq integer_2 ]

integer_1 is equal to integer_2

[integer_1 -ne integer_2 ]

integer_1 is not equal to integer_2

[integer_1 -gt integer_2 ]

integer_1 is greater than integer_2

[integer_1 -ge integer_2 ]

integer_1 is greater than or equal to integer_2

[integer_1 -ge integer_2 ]

integer_1 is less than integer_2 .

[integer_1 -le integer_2 ]

integer_1 is less than or equal to integer_2

Let's write the shell script, test03.sh, for learning the various numerical test operators' usage:

#!/bin/bash num1=10 num2=30 echo $(($num1 < ...

Get Learning Linux Shell Scripting - Second Edition 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.