(square bracket) commands (
can compare two numbers.
But it's an error if one of the numbers you test is stored in a shell variable
that's empty or doesn't exist.
For example, an empty
variable here will give you a
if [ "$num" -gt 0 ]
To stop syntax errors, add a leading zero, like this:
if [ "0$num" -gt 0 ]
In that case, if
is empty, the test will compare
, the test will be true (because
)-and so on, just as it should be.