indirect expansion
The bash form ${!name}, which reads the value of the variable whose name is stored in name.
In more detail
If name holds prod_host, ${!name} gives the value of prod_host, the safe replacement for eval when choosing a variable at run time. It only reads; use a nameref to write.
Example
name="${env}_host"; echo "${!name}"Related terms
- nameref — A bash 4.3 variable declared with declare -n or local -n that acts as another name for a variable named by its value.
- eval — A shell builtin that joins its arguments into one string and runs that string as a command, as if you had typed it.
- parameter expansion — Replacing a dollar sign and a variable name with the variable's value, optionally transformed by an operator inside curly braces.
Taught in
- eval, And What To Use Instead — Bash Scripting & Command Line Automation