请教:如何读取以变量值为名的变量的值
发表于 : 2009-03-09 12:51
如题,有点绕,其实就是:
有一个变量A,A中存储的内容是另一个变量的名字,我想得到这“另一个变量”的值,怎么通过A来得到?
欢迎大家发言~
有一个变量A,A中存储的内容是另一个变量的名字,我想得到这“另一个变量”的值,怎么通过A来得到?
欢迎大家发言~
代码: 全选
ubuntu@ubuntu:~$ a=b
ubuntu@ubuntu:~$ b='it works!'
ubuntu@ubuntu:~$ echo $a
b
ubuntu@ubuntu:~$ echo $b
it works!
ubuntu@ubuntu:~$ eval echo \$$a
it works!
ubuntu@ubuntu:~$ eval c=\$$a
ubuntu@ubuntu:~$ echo $c
it works!
ubuntu@ubuntu:~$
可不可以介绍一下'!'的功能?谢谢.cnkilior 写了:c代码: 全选
a=b b=c echo ${!a}
eval is useful when cmd contains something which needs to be evaluated by the shell. The typical case would be when you have a variable containing the index of an argument you want to access.eexpress 写了:这bt的,没用过。估计lz是需要数组来操作什么,却思路不对。