shell判断字符串长度是否为0

语法

-z STRING

示例

#!/bin/bash
read -s -p "请输入密码 " pass
echo 
if test -z $pass 
then
    echo "密码不能为空!"	
    exit 1
fi

shell判断字符串是否相等

语法

STRING1 = STRING2

示例

#!/bin/bash
pass="oir"
echo 
if test "$pass" = "oir"
then
    echo "password is correct!"
fi

shell判断字符串是否不相等

语法

STRING1 != STRING2

示例

#!/bin/bash
pass="oir"
echo 
if test "$pass" != "oir"
then
    echo "wrong password!"
fi
字符串比较
日期:2019-04-16 23:59:04 来源:oir作者:oir