On 12/15/14 6:41 AM, Dan Douglas wrote: > To me the biggest problem is what happens when you explicitly request a scalar > assignment. (I even specified a[1] to ensure it's not an "a vs. a[0]" issue.) > > bash -c 'typeset -a a; b="(foo bar)"; typeset a[1]=$b; typeset -p a; > printf "<%s> " "${a[@]}"; echo' > declare -a a='([0]="foo" [1]="bar")' > <foo> <bar> > > This doesn't fit with my understanding of how it should work. Otherwise I > think > the way declare's arguments are interpreted based upon their form and current > set of attributes is pretty well understood, albeit undocumented.
If you use a subscript with typeset, even when you're attempting an assignment, the following text from the manual page applies: "To explicitly declare an indexed array, use declare -a name (see SHELL BUILTIN COMMANDS below). declare -a name[subscript] is also accepted; the subscript is ignored." Bash treats `typeset name[subscript]' as identical to `typeset -a name' or `typeset -a name[subscript]'. It's syntax picked up from old versions of ksh, which actually used the subscript to size the array. Maybe it should attempt subscript assignment, but it never has. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/