更新时间:2023-01-19 21:54:46
借助 Bash的参考手册介绍如何使用参数扩展的一个很棒的功能做一些间接。在你的情况,你有兴趣在寻找一个变量,其名称由其他两个变量定义的内容:
The Bash Reference Manual explains how you can use a neat feature of parameter expansion to do some indirection. In your case, you're interested in finding the contents of a variable whose name is defined by two other variables:
server_list_all="server1 server2 server3"
var1=server
var2=all
combined=${var1}_list_${var2}
echo ${!combined}
指当感叹号组合
表示使用其名称由内容定义的变量组合
The exclamation mark when referring to combined
means "use the variable whose name is defined by the contents of combined
"