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

Re: issues with ${array[x][y]}



2018-03-06 15:16:44 +0000, Stephane Chazelas:
[...]
> string[1]=x
> 
> and reference ${array[1][1]}
> 
> but:
> 
> $ a[1][1]=b
> zsh: no matches found: a[1][1]=b
> $ ((a[1][1] = 2))
> zsh: bad base syntax
> $ typeset 'a[1][1]=2'
> zsh: not an identifier: a[1][1]
[...]

Also:

$ a=(213 345)
$ echo $((a[1])) $((${a[1]}))
213 213
$ echo $((a[1][2]))
zsh: bad base syntax
$ echo $((${a[1][2]}))
1

For reference, in ksh93, ${a[1][2][3]} is used for its
multi-dimensional arrays, and

${a[1][2]}
$((a[1][2]))
a[1][2]=x
((a[1][2] = 3))
typeset -n b='a[1][2]'

are recognised consistently, but ${a[1][2]=x} is buggy:

$ ksh -c ': ${a[1][2]=x}; typeset -p a'
typeset -a a=([1]=([0]=) )
$ ksh -c 'a[1][2]=x; typeset -p a'
typeset -a a=([1]=([2]=x) )

(of course, it's more important for ksh93, as multi-dimensional
arrays would be less useful without, while zsh's a[1][2] setting
the second character of the first element of a is not going to
be often useful (except maybe for the $mapfile case mentioned
earlier))

-- 
Stephane



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