Variable as bash array index?

前端 未结 2 636
执笔经年
执笔经年 2021-02-02 09:43
#!/bin/bash

set -x

array_counter=0
array_value=1

array=(0 0 0)

for number in ${array[@]}
do
    array[$array_counter]=\"$array_value\"
    array_counter=$(($array_co         


        
2条回答
  •  醉话见心
    2021-02-02 10:15

    Bash seems perfectly happy with variables as array indexes:

    $ array=(a b c)
    $ arrayindex=2
    $ echo ${array[$arrayindex]}
    c
    $ array[$arrayindex]=MONKEY
    $ echo ${array[$arrayindex]}
    MONKEY
    

提交回复
热议问题