2014-12-03 119 views
5

我使用4.2.53(1) - 释放,这是由Fedora 20.'声明-A X' VS '声明-A X =()'

下面的两个代码的行为的运行件不同的是,有谁能说出原因吗谢谢。

[hidden]$ unset x; declare -p x; function f() { declare -A -g x; x[10]=100; }; f; declare -p x; 
-bash: declare: x: not found 
declare -A x='([10]="100")' 
[hidden]$ unset x; declare -p x; function f() { declare -A -g x=(); x[10]=100; }; f; declare -p x; 
-bash: declare: x: not found 
declare -A x='()' 

回答

5

这是4.0-4.2中的一个错误。这是fixed in 4.3

ddd. Fixed several bugs that caused `declare -g' to not set the right global 
    variables or to misbehave when declaring global indexed arrays. 

这里有4.3,他们的行为相同的结果:

$ echo $BASH_VERSION 
4.3.11(1)-release 

$ unset x; declare -p x; function f() { declare -A -g x; x[10]=100; }; f; declare -p x; 
bash: declare: x: not found 
declare -A x='([10]="100")' 

$ unset x; declare -p x; function f() { declare -A -g x=(); x[10]=100; }; f; declare -p x; 
bash: declare: x: not found 
declare -A x='([10]="100")'