【发布时间】:2011-08-01 10:20:07
【问题描述】:
在使用 shell 脚本编写 if 条件时,有人能告诉我 -z 选项的意义吗?
让我粘贴我正在查看的确切条件
if [[ "x$do_clean_flag" = "x-clean" && -z "$show_me_flag" && "$verify" = true ]]
【问题讨论】:
在使用 shell 脚本编写 if 条件时,有人能告诉我 -z 选项的意义吗?
让我粘贴我正在查看的确切条件
if [[ "x$do_clean_flag" = "x-clean" && -z "$show_me_flag" && "$verify" = true ]]
【问题讨论】:
来自“帮助测试”:
-z STRING True if string is empty.
【讨论】:
-z 检查是否定义了 $show_me_flag
查看测试手册(1)
【讨论】:
-z (something) 表示如果 (something) 为 NULL 则返回 true
http://unixhelp.ed.ac.uk/CGI/man-cgi?test
建议零长度也返回 true,我建议在您的机器上进行“人工测试”以检查系统上的确切措辞。
【讨论】:
-z NULL 返回 false。 -z 只是测试字符串是否为空。所以-z "" 返回 true。
The test utility evaluates the expression and, if it evaluates to true, returns a zero (true) exit status; otherwise it returns 1 (false). If there is no expression, test also returns 1 (false). 所以,1 表示假,0 表示真,在这里。 进一步说明:-z string True if the length of string is zero.