The POSIX specification for the test and [ commands includes a few arithmetic tests for integers:
- [ "$a" -eq "$b" ]: Equal
- [ "$a" -ne "$b" ]: Not equal
- [ "$a" -lt "$b" ]: Less than
- [ "$a" -le "$b" ]: Less than or equal to
- [ "$a" -gt "$b" ]: Greater than
- [ "$a" -ge "$b" ]: Greater than or equal to
Sometimes using these tests with expansion of arithmetic expressions can be unwieldy to write; for example, if we wanted to test whether the value of the bytes variable, divided by 1,000, was greater than ...