動態建立新數組並為其新增值

動態建立新數組並為其新增值

for (( i=1;i<5;i++ )) do arr$i[$i]=$i 完成

這給了我錯誤 ./test.sh: line 2: arr1[1]=1: command not find ./test.sh: line 2: arr2[2]=2: command not found ./test.sh: line 2: arr3[3]=3: 未找到指令./test.sh: 第2 行: arr4[4]=4: 找不到指令

如何解決這個問題?先致謝

答案1

使用letbash 內建關鍵字:

for (( i=1;i<5;i++ )); do let arr$i[$i]=$i; done

相關內容