是否有可能建立从在bash其他变量的变量名? [英] Is it possible to build variable names from other variables in bash?
本文介绍了是否有可能建立从在bash其他变量的变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为pretty可怕的标题道歉 - 而质量差的后 - 但我基本上想要做的是这样的:
I apologise for the pretty terrible title - and the poor quality post - but what I basically want to do is this:
for I in 1 2 3 4
echo $VAR$I # echo the contents of $VAR1, $VAR2, $VAR3, etc.
显然,上述不工作 - 这将(我认为)尝试和回声名为 $ VAR $ I
变量在Bash中这是可能的。
Obviously the above does not work - it will (I think) try and echo the variable called $VAR$I
Is this possible in Bash?
推荐答案
是的,但不这样做。使用数组来代替。
Yes, but don't do that. Use an array instead.
如果你仍然坚持做这样的说法...
If you still insist on doing it that way...
$ foo1=123
$ bar=foo1
$ echo "${!bar}"
123
这篇关于是否有可能建立从在bash其他变量的变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文