I would like to know if I can substitute a variable twice.
For example:
#global variable
TEST_SERV_EXT=""
#variables become from myconf.sh
TEST_SERV_EXT_FO='foo01'
TEST_SERV_EXT_BR='bar01'
I want dynamically construct those last two and assign them in TEST_SERV_EXT.
I tried something like this ${$TEST_SERV_COMP} but I'm getting "bad substitution" message.
I need something like php's feature "$$" or tcl's subst command.
Regards, thandem
Bash performs variable substitution before the command is really executed. The Linux Bash Shell searches for all the ‘$’ sign before executing the command and replace it with the value of variable. The process of Bash Variable substitution is performed only once.
It doesn't do a “double substitution” because there's no such feature in any of the common shells (not with this syntax anyway).
Bash variables and command substitution Using variables to refer to data, including the results of a command. An essential feature of programming is the ability to use a name or a label to refer to some other quantity: such as a value, or a command. This is commonly referred to as variables.
Command substitution The standard output of a command can be encapsulated, much like a value can be stored in a value, and then expanded by the shell. This is known as command substitution.
TEST_SERV_COMP=TEST_SERV_EXT_FO
TEST_SERV_EXT=${!TEST_SERV_COMP}
Look for indirect expansion
in the bash manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With