-1

If you declare an array like this

declare -a test

you can echo the value like this

i=2
echo ${test[i]}

or

i="1+1" 
echo ${test[i]}

why the second form is accepted? i need a complex answer thanks

Wisp Ever
  • 35
  • 6

1 Answers1

4

See man bash:

The subscript is treated as an arithmetic expression that must evaluate to a number.

Complex enough?

choroba
  • 231,213
  • 25
  • 204
  • 289