shell-条件判断-字符串比较

字符串比较

字符串比较

参数 说明
== 相等则为真
!= 不相等则为真

参数 说明
str1= str2 相等则为真
str1 != str2 不想等比较
str1< str2 str1 < str2为true
str1> str2 str1 > str2为true
-n str1 str长度不是0则为true
-z str1 str1长度为0则为true

shell-条件判断-字符串比较
字符串的大小与字母表顺序有关。
shell-条件判断-字符串比较
检查变量是否是空值。
shell-条件判断-字符串比较shell-条件判断-字符串比较
注意未定义的变量的使用方法" $var"
shell-条件判断-字符串比较shell-条件判断-字符串比较没有双引号括起来,shell会认为后面就是一个没有指定的空值。