[ "$STR" = "" ] 和 [ -z $STR ] 有什么不同
时间:2007-04-16 来源:huanghaojie
[ "$STR" = "" ] 和 [ -z $STR ] 有什么不同
#!/bin/bash
if [ "$1" = "" ]
then echo null ok
fi
if [ -z $1 ]
then echo 0 ok
fi
一个小脚本,自己测试
[root@rhel5 ~]# ./test.sh
null ok
0 ok
[root@rhel5 ~]# ./test.sh ''
null ok
0 ok
[root@rhel5 ~]# ./test.sh ' '
0 ok
应该明白了吧,空格不是null,但是长度为0
#!/bin/bash
if [ "$1" = "" ]
then echo null ok
fi
if [ -z $1 ]
then echo 0 ok
fi
一个小脚本,自己测试
[root@rhel5 ~]# ./test.sh
null ok
0 ok
[root@rhel5 ~]# ./test.sh ''
null ok
0 ok
[root@rhel5 ~]# ./test.sh ' '
0 ok
应该明白了吧,空格不是null,但是长度为0
相关阅读 更多 +
排行榜 更多 +