我正在尝试在 shell 脚本中生成动态 var 名称,以循环处理一组具有不同名称的文件,如下所示:
SAMPLE1='1-first.with.custom.name'
SAMPLE2='2-second.with.custom.name'
for (( i = 1; i <= 2; i++ ))
do
echo SAMPLE{$i}
done
Run Code Online (Sandbox Code Playgroud)
我希望输出:
1-first.with.custom.name
2-second.with.custom.name
Run Code Online (Sandbox Code Playgroud)
但我得到了:
SAMPLE{1}
SAMPLE{2}
Run Code Online (Sandbox Code Playgroud)
是否可以即时生成 var 名称?