在Bash中分配给动态变量名称 [英] Assign to dynamic variable name in Bash
本文介绍了在Bash中分配给动态变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为名称中包含变量的变量赋值?
How do I assign a value to variable that has a variable in its name?
var1="file"
var2_$var1="folder"
上面的代码给了我错误-bash: var2_file=folder: command not found
.我很好奇知道如何分配给变量名中的另一个变量.
The code above gives me the error -bash: var2_file=folder: command not found
. I was curious to know how to assign to a variable with another variable in its name.
Bash的版本是"GNU bash,版本4.1.2"
Version of Bash is "GNU bash, version 4.1.2"
推荐答案
使用 bash
,您可以使用 declare
:
declare var2_$var1="123"
这篇关于在Bash中分配给动态变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文