2014-12-03 14 views
5

ja pomocą 4.2.53 -release (1), który jest prowadzony przez Fedora 20.'stwierdzenie -A X' vs "stwierdzenie -A X =()

Następujące dwa fragmenty zachowują inaczej, czy ktokolwiek może powiedzieć dlaczego? Dzięki.

[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='()' 

Odpowiedz

5

To był błąd w wersji 4.0-4.2. Było 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. 

Oto wynik na 4.3, gdzie zachowują się identycznie:

$ 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")' 
Powiązane problemy