-z 在 Bash 中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18096670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:01:01  来源:igfitidea点击:

What does -z mean in Bash?

bash

提问by Noich

I'm looking at the following code:

我正在查看以下代码:

if [ -z  ]; then
        echo "usage: ...

(The 3 dots are irrelevant usage details.)
Maybe I'm googling it wrong, but I couldn't find an explanation for the -zoption.

(这 3 个点是不相关的使用细节。)
也许我在谷歌上搜索错了,但我找不到该-z选项的解释。

回答by Yu Hao

-z stringTrue if the string is null (an empty string)

-z string如果字符串为空(空字符串),则为真

回答by Noich

-z

string is null, that is, has zero length

String=''   # Zero-length ("null") string variable.

if [ -z "$String" ]
then
  echo "$String is null."
else
  echo "$String is NOT null."
fi     # $String is null.

回答by knittl

test -zreturns true if the parameter is empty (see man shor man test).

test -z如果参数为空,则返回 true(参见man shman test)。

回答by mohit

The expression -z stringis true if the length of string is zero.

-z string如果字符串的长度为 ,则表达式为真zero