The mnemonic for -ne
is 'not equal'; it does an arithmetic comparison on the two values for inequality.
The mnemonic for -n
is 'not empty'; it tests whether the argument ("$1"
in this case) is an empty string. If $1
is defined and has a value other than the empty string, the test will be true.
See Bash conditional expressions for more details.
The test
command, also known as [
, supports the other numeric comparison operators too: -lt
(less than), -le
(less than or equal to), -gt
(greater than), -ge
(greater than or equal to), and -eq
(equal). The -z
operator tests for a zero length string — but note that the argument must be enclosed in double quotes, though ([ -z "$variable" ]
) as otherwise there is no argument for -z
to test.
There are many other test operators; this is not an exhaustive list.