gpt4 book ai didi

shell - 如何在Shell Script中访问其名称由各种字符串组成的变量?

转载 作者:行者123 更新时间:2023-12-04 04:37:13 39 4
gpt4 key购买 nike

所以,这类似于通过引用传递参数。我想访问一个变量(echo),它的名字是来自不同字符串的组合字符串。一个简单的例子如下:

A1=999
n="1"
B="A$n"

我想要的是,当我做 echo $B ,它会返回 999 .如果需要进一步解释,请告诉我。谢谢。

最佳答案

你正在寻找间接

echo ${!B}

来自 bash 手册
   ${!prefix*}
${!prefix@}
Expands to the names of variables whose names begin with prefix,
separated by the first character of the IFS special variable.

关于shell - 如何在Shell Script中访问其名称由各种字符串组成的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19553820/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com