Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh -n does not detect incorrect associative array declaration



On Mar 23,  9:23am, Peter Stephenson wrote:
} Subject: Re: zsh -n does not detect incorrect associative array declaratio
}
} On Tue, 22 Mar 2016 23:40:54 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > Contrast this with ksh where associative array assignments look like
} > 
} > fn=( [foo_key]=foo_val [bar_key]= )
} > 
} > forcibly changes the type of "fn" to become an associative array
} 
} Off the original topic, but actually it doesn't, at least not in bash.

I'd forgotten that bash even supports that syntax, but in any case it
does change the type in ksh.

$ typeset -a x
$ typeset -p x
typeset -a x
$ x=( [a]=1 [b]=2 )
$ typeset -p x
typeset -A x=([a]=1 [b]=2)
$ 

Bash allows you to set numerically-indexed positions in a normal array
with the ( [key]=value ) syntax, and also outputs the arrays that way
with "typeset -p".  You can have sparse arrays in bash.



Messages sorted by: Reverse Date, Date, Thread, Author