我试图在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}
有可能在运行中生成变量名吗?