Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 bash 中,如果我有:
y=10 x='y' echo $x # prints 'y'
现在我想$y通过 $x:
$y
echo ${$x} # error: "bad substitution"; I want to print 10
如何使用 name 查找变量值$x?
$x
请参阅 bash 手册中的参数扩展:
echo ${!x}
转义外部美元符号时eval用于间接引用
eval
eval echo "\${$x}"
分配给变量
eval "z=\${$x}" echo "$z" # 10