这个检查的条件是什么:if[-z$1]



我在shell脚本中有三个条件,如果它们在英语中的意思是什么,我可以得到帮助吗。此外,我将来如何使用手册页来查找类似的命令?

条件如下:

  1. if [ -z $1 ]

  2. if [ ! -r $1 ]

  3. if [ -n $3 ]

这里的诀窍是[不是标点符号,而是命令的名称,也称为test。所以您需要的帮助页面是man test

在该页面上,您可以看到列出的选项:

-z STRING
the length of STRING is zero
! EXPRESSION
EXPRESSION is false
-r FILE
FILE exists and read permission is granted
-n STRING
the length of STRING is nonzero

由于bash包含该命令的内置实现,您还可以在man bash和bash参考手册中找到相关信息。

参见man bash:中的"条件表达式">

-r file
True if file exists and is readable.
-n string
True if the length of string is non-zero.   
-z string
True if the length of string is zero.

有趣的是,!没有在[ ... ]的上下文中记录,但它的含义与其他上下文相同。您可以在help testman bash中的"SHELL内置命令"部分[ expr ]中找到解释。

最新更新