我正在尝试在shell脚本中生成动态变量名,以便在循环中处理一组具有不同名称的文件,如下所示:
#!/bin/bash
SAMPLE1='1-first.with.custom.name'
SAMPLE2='2-second.with.custom.name'
for (( i = 1; i <= 2; i++ ))
do
echo SAMPLE{$i}
done
我期望的输出是:
1-first.with.custom.name
2-second.with.custom.name
但我得到了:
SAMPLE{1}
SAMPLE{2}
能否在运行时生成变量名称?