shell 判断字符串为空的方法汇总
程序员文章站
2022-05-25 16:33:33
...
1.-z判断
-z string
if [ -z $str ]
then
echo "是空字符串"
fi
2.拼加字符串再比较
if [ "Z$strZ" = "ZZ" ]
then
echo "是空字符串"
fi
3.直接使用变量判断
if [ "$str" ]
then
echo "非空"
else
echo "空"
fi
-z string
if [ -z $str ]
then
echo "是空字符串"
fi
2.拼加字符串再比较
if [ "Z$strZ" = "ZZ" ]
then
echo "是空字符串"
fi
3.直接使用变量判断
if [ "$str" ]
then
echo "非空"
else
echo "空"
fi