- Use
test
with the -eq (equality for numbers) operator
test 4 -eq 5; echo $?
Since anything other than 0 as an exit status signals failure,
this means that the equality test has failed.
- Use the -eq operator with the same number on both sides
test 4 -eq 4; echo $?
Since 0 means success, this means that the expression evaluated to true.
- Use
test
with the -ne (not equal for numbers) operator
test 4 -ne 5; echo $?
0 means true.
- Use -ne again
test 4 -ne 4; echo $?
1 means false.
- Use
test
with the -gt (greater than) operator
test 4 -gt 5 ; echo $?
test 5 -gt 4 ; echo $?
- Use the -ge (greater than or equal to) operator
test 5 -ge 4 ; echo $?
test 5 -ge 5 ; echo $?
- Use the -lt (less than operator)
test 4 -lt 5 ; echo $?
test 5 -lt 4 ; echo $?
- Use the -le (less than or equal to) operator
test 4 -le 5 ; echo $?
test 4 -le 4 ; echo $?