组合两个变量以形成 Bash 中另一个变量的标识符
Combine two variables to form the identifier for another variable in Bash
我希望能够获取两个变量的值并将它们连接在一起以形成 bash 脚本中另一个变量的标识符。
final_answer="we did it"
one="final"
two="answer"
t="${one}_${two}"
echo ${$t} # would like this to echo we did it; currently give "${$t}: bad substitution"
不确定这是否可能,但似乎 bash 会以某种方式具有这种能力。
谢谢!
$ echo "${!t}"
we did it
我希望能够获取两个变量的值并将它们连接在一起以形成 bash 脚本中另一个变量的标识符。
final_answer="we did it"
one="final"
two="answer"
t="${one}_${two}"
echo ${$t} # would like this to echo we did it; currently give "${$t}: bad substitution"
不确定这是否可能,但似乎 bash 会以某种方式具有这种能力。
谢谢!
$ echo "${!t}"
we did it