= |
判断是否相等,如果相等为真 |
!= |
判断是否不相等,如果不相等为真 |
-z |
判断字符串的长度为0,如果为0则为真 |
-n |
判断字符串长度不为0,如不为0则为真 |
1、判断字符串是否相等
char1='1ruk'
char2='ldjsll'
if test $char1 = $char2/; then echo 'char1等于char2'; else echo 'char1不等于char2'; fi
2、判断字符串是否不等
char1='1ruk'
char2='ldjsll'
if test $char1 != $char2
then
echo 'char1不等于char2!'
else
char1等于char2!'
fi
3、判断字符串长度是否为0
num1="ru1noob"
if test -z $num1
then
echo 'num1长度为0!'
else
echo 'num1长度不为0!'
fi
4、判断字符串长度不为0
num1="ru1noob"
if test -n $num1
then
echo 'num1长度不为0!'
else
echo 'num1长度为0!'
fi