As well as testing string values of bash scripts, we can test for integer values and whole numbers. Another way of testing the input of a script is to count the numbers of positional parameters and also test if the number is above 0:
test $# -gt 0
Or using the brackets, as follows:
[ $# -gt 0 ]
When in a relationship, the top positional parameters of the $# variable represent the number of parameters passed to the script.
There are many tests that can be done for numbers:
- number1 -eq number2: This checks if number1 is equal to number2
- number1 -ge number2: This checks if number1 is greater than or equal to number2.
- number1 -gt number2: This checks if number1 is greater than number2
- number1 -le number2: This checks if number1 is smaller than or equal to number2
- number1 -lt number2: This checks if number1 is smaller than number2
- number1 -ne number2: This checks if number1 is not equal to number2