我正在使用由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='()'
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] 删除。
我来说两句