Shell脚本:shell脚本中的-z意味着什么?

时间:2015-09-23 23:01:21

标签: shell sh

我有一个代码可以做这样的事情:

if [ -z "$SOME_VARIABLE" ]; then
    echo "something something 1"
else
    echo "something something 2"
fi

我不知道“-z”在这里做了什么。有人可以解释一下吗?

2 个答案:

答案 0 :(得分:1)

[是一个与其他命令一样的命令,只是名字不同寻常。您可以查看[手册页以查看其标志的含义。

$ man [

<snip>

       -n STRING
              the length of STRING is nonzero

       STRING equivalent to -n STRING

       -z STRING
              the length of STRING is zero

答案 1 :(得分:1)

  

-z string:如果字符串为空,则为真。

http://linuxcommand.org/wss0090.php