小编pQB*_*pQB的帖子

如何动态生成新的 var 名称

我正在尝试在 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 名称?

bash shell-script variable-substitution

5
推荐指数
2
解决办法
3615
查看次数

标签 统计

bash ×1

shell-script ×1

variable-substitution ×1