<分区>
知道为什么会这样吗?为什么我必须手动显式重新分配变量,但如果我在变量名称中有另一个变量却不能这样做?
脚本:
#!/bin/bash
a_1=1
a_2=1
for temp in 1 2
do
a_$temp="2"
echo $((a_$temp))
done
a_1=2
a_2=2
echo $a_1
echo $a_2
输出:
[dgupta@della4 Rates_Of_Quenching]$ ./test.sh
./test.sh: line 8: a_1=2: command not found
1
./test.sh: line 8: a_2=2: command not found
1
2
2