Quoting from the Bash manual:
An indexed array is created automatically if any variable is assigned to using the syntax
name[subscript]=value
The subscript is treated as an arithmetic expression that must evaluate to a number.
Is subscript
- an arithmetic expression, or
- an arithmetic expansion where
$((
and))
are ignored and only an arithmetic expression is there?
In other words, is there a step of arithmetic expansion here, just like when interpreting a command with arithmetic expansion?
For example,
$ declare -p myarr
declare -a myarr='([0]="0" [2]="3" [3]="9999")'
$ echo ${myarr[1+2]}
9999
$ echo ${myarr[$((1+2))]}
9999