什么';在bash中是一个空字符串
我刚刚在bash手册中找到了以下片段:什么';在bash中是一个空字符串,bash,Bash,我刚刚在bash手册中找到了以下片段: A variable may be assigned to by a statement of the form name=[value] If value is not given, the variable is assigned the null string. 空字符串的确切含义是什么?是例如 local empty 相当于 local empty="" “空字符串”是长度为零的字符串。在您的示例中,两者是相同的 一个简单的测试: #
A variable may be assigned to by a statement of the form
name=[value]
If value is not given, the variable is assigned the null string.
空字符串
的确切含义是什么?是例如
local empty
相当于
local empty=""
“空字符串”是长度为零的字符串。在您的示例中,两者是相同的
一个简单的测试:
#!/bin/bash
go(){
local empty
local empty2=""
[[ -z $empty ]] && echo "empty is null"
[[ -z $empty2 ]] && echo "empty2 is null"
[[ $empty == $empty2 ]] && echo "They are the same"
}
go
印刷品:
empty is null
empty2 is null
They are the same
“空字符串”是长度为零的字符串,但“空字符串”不是真的<如果字符串不是空字符串(
[]
),并且长度不为零([-n]
),那么code>test有不同的表达式进行测试,通过比较[]&&echo“true”
的输出与[-n]&&echo“true”
的输出,可以看出这些表达式是不同的。嗯,好的,在深入研究之后,显然,[-n]
没有使用-n
作为操作数,而是使用测试的第一种形式来测试字符串“-n”。尽管如此,bash文档中有些地方似乎在一句话中明确提到了null字符串和空字符串,这对我来说意味着它们是不同的。或者我想在文档中看到支持“空字符串”与“空字符串”相同的声明的内容。