4

我刚刚在 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.

究竟是什么意思null string?是例如

local empty

相当于

local empty=""

?

4

1 回答 1

6

“空字符串”是长度为零的字符串。在您的示例中,两者都是相同的。

一个简单的测试:

#!/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
于 2012-05-24T08:03:20.440 回答