'声明-A x'与'声明-A x =()'

Kan Li :

我正在使用由Fedora 20运行的4.2.53(1)-release。

以下两段代码的行为不同,谁能说出原因?谢谢。

[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='()'
那个人:

这是4.0-4.2中的错误。它已在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" )'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章