有时候我们需要比较两个数字的大小关系,这时候就要用到关系运算符。关系运算符只支持数值运算,不支持字符运算。
上面输出:a not great than b
。
除了支持大于运算符,Shell 语言还支持下面这些关系运算符:
-
-eq
:检测两个数是否相等,相等返回 true。 -
-ne
:检测两个数是否不相等,相等返回 true。 -
-gt
:检测左边的数是否大于右边的,如果是返回 true。 -
-lt
:检测左边的数是否小于右边的,如果是返回 true。 -
-ge
:检测左边的数是否大于等于右边的,如果是返回 true。 -
-le
:检测左边的数是否小于等于右边的,如果是返回 true。