1.1 The following table is a common two-dimensional comparison operator
We can also see through the man test
Tips
(1) The "<" symbol is less than the meaning, if[["$a" < "$b"]], if[["$a" \< "$b"]. You need to escape in parentheses because the shell is also redirected with < and >.
(2) the ">" symbol is greater than the meaning, if[["$a" > "$b"]], if[["$a" \> "$b"]. You need to escape in parentheses because the shell is also redirected with < and >.
(3) The "=" symbol equals the meaning, if[["$a" = "$b"]],if[["$a" = "$b"]. Escaping is not required in single [].
Special tips:
"=" and "! = "use in [] does not need to escape, the symbol containing" > "and" < "in the [] number is used to escape, the result of the number is not escaped may not be error, but the result may not be.
Example 1: Two-time numeric comparisons
Actual test results concluded:
(1) integer plus double quotes is also true.
(2) [[]] use-EQ and other writing is also right, [[]] with > may not be correct, only the first, the logical result is not correct.
(3) [] using the > Code syntax error, the logical result is not correct.
Work scenario: recommended []-eq usage.
Summary: integer comparison recommended usage
[$num –eq $num 2] Note the spaces, and compare symbols.
(($num 1> $num 2)) No spaces, general mathematical comparison symbols.
Integer comparisons can be double-quoted or non-additive.
System Script Example Grep–w "-eq"/etc/init.d/nfs
Shell Scripting Learning notes-integer Two-dimensional comparison operator