存储信息循环时递增变量bash

Increment variable while storing information loop bash

我需要增加 key,同时还要存储信息。例如:

key1=value
key2=value

等等...

count = 7

while [ $count -gt -1 ]
do
        key$count=${array[$count]}
        let count=$count-1
        echo $key
done

您可以在此处使用 declare 指令:

array=(10 20 30 40 50 60 70 80 90)

for ((count=7; count > -1; count--)); do
   declare "key$count"="${array[$count]}"
done