If the first character of parameter is an exclamation point (!), and parameter is not a nameref, it introduces a level of variable indirection. Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself. This is known as indirect expansion. If parameter is a nameref, this expands to the name of the variable referenced by parameter instead of performing the complete indirect expansion. The exceptions to this are the expansions of ${!prefix*} and ${!name[@]} described below. The exclamation point must immediately follow the left brace in order to introduce indirection.
This is called variable indirect expansion.
$ hello="this is some text" # we set $hello
$ var="hello" # $var is "hello"
$ echo "${!var}" # we print the variable linked by $var's content
this is some text
As you see, it is a way to define "variable variables". That is, to use variables whose content is the name of another variable.、
其实就是间接引用,类似指针的味道。调用{指定变量的内容}作为变量时的内容。
参考
https://unix.stackexchange.com/questions/340535/how-does-one-parse-i-and-what-does-it-mean

本文深入探讨了Bash shell中的一种高级特性——间接变量展开。通过实例演示了如何使用此功能来创建“变量变量”,即变量内容指向另一个变量名。这种机制允许更灵活地操作和引用变量,对于复杂脚本编写尤为有用。
858

被折叠的 条评论
为什么被折叠?



