test 语句中的 字符串比较

test "$string" =="" 这个很有效,必须用引号

否则会出现 test $string =="" 和test $string != "" 都为真的情况看

字符串为空 test -z string

字符串不为空 test -z sting

文件为空 test !- empty

注意:中间要有空格

比如 判断 某个日期$date 是否为空

echo $date;

if test "$date"==""

then

date="2009-12-28";

fi;

echo $date;

date初时为"2008-12-27",则因为没有空格导致进入if判断

test和 []效果是一样的,但是必须要有空格 test "$date" == ""

原文地址:https://www.cnblogs.com/pony/p/1372759.html