Variable as bash array index?

前端 未结 2 635
执笔经年
执笔经年 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

    Your example actually works.

    echo ${array[@]}
    

    confirms this.

    You might try more efficient way of incrementing your index:

    ((array_counter++))
    

提交回复
热议问题