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


 

test.sh

#!/bin/bash
s1=""
if test $s1 ;then
echo "length is not zero"
else
echo "the length is 0"
fi
s2="shell"
if test $s2 ;then
echo "length is not 0"
else
echo "the length is 0"
fi

执行

sudo chmod +x test.sh
./test.sh

输出

the length is 0
length is not 0

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM