shell判空

a="a"
b="a"
if [ $a = $b ] 
then
 echo "="
else
 echo "!=" 
fi

#-z 检查str1的长度是否为0
if [ -z $a ]
then
 echo "zero"
else
 echo "not zero" 
fi

#-n 检查str1的长度是否非0,注意需加""
c=""
if [ -n "$c" ]
then
 echo "not zero"
else
 echo "zero" 
fi

=
not zero
zero

猜你喜欢

转载自xiangjie88.iteye.com/blog/2390946