3
在bash,如果我有:查找变量值
y=10
x='y'
echo $x # prints 'y'
现在我想通过$ X $y
:
echo ${$x} # error: "bad substitution"; I want to print 10
如何查找与变量值名字$x
?
在bash,如果我有:查找变量值
y=10
x='y'
echo $x # prints 'y'
现在我想通过$ X $y
:
echo ${$x} # error: "bad substitution"; I want to print 10
如何查找与变量值名字$x
?
见参数扩展的bash手册中:
echo ${!x}
检查[EVAL] (http://www.linuxquestions.org/questions/programming-9/basic-bash-how-to-use-eval-to-evaluate-varia ble-names-made-of-arbitrary-strings-775622 /) – m0skit0
@ m0skit0 please,no eval - 它具有实质性的安全隐患,详见http://mywiki.wooledge.org/BashFAQ/048。正确的方法,间接变量,记录在http://mywiki.wooledge.org/BashFAQ/006 –
一切都有好的和坏的用途。你只需要知道如何使用它。 – m0skit0