create variable name in bash
Hi,
I have a bash script which takes it's configuration options from another file. The options are variables like: Code:
abc_hello=1 Point being, the name consists of two or more parts. The script loads the conf file: Code:
. /path/to/config.conf Code:
echo $xyz_tree Problem is, there are many variables and they change but are systematic. The script can actually generate names like abc_hello correctly from other settings in the config file and then, hopefully, use them in loops. How can I force the generated name to act as a variable? For example: Code:
hello_world=10 Code:
echo "$"$one"_"$two"" Is it possible at all with bash 2? I have tried various combinations but haven't had any luck. I hope I'm just missing some kind of bash trick. Thanks. |
Quote:
Code:
#!/bin/bash |
Quote:
|
The bourne shell compatible way to do it is with eval:
Code:
eval varvalue=$varname |
All times are GMT -5. The time now is 08:48 AM. |