linux shell 中比较数字 、字符串 大小

来源:互联网 发布:华为荣耀网络拒绝接入 编辑:程序博客网 时间:2024/05/16 07:57

数字的比较:
-eq 相等(equal)
-ne 不等(not equal)
-gt 大于(greater than)
-lt 小于(less than)
-ge 大于等于 (greater than or equal)
-le 小于等于 (less than or equal)

字符串的比较:
[ $str1 = $str2 ] 等于
[ $str1 != $str2 ] 不等于
[ -z $str ] 空字符串返回true
[ -n $str ] 或者 [ $str ] 非空字符串返回true

0 0