Reputation: 31
I have a config file in unix as
Variable_name:sequences:Status
ABC:1234:/path/txt
and I have a script in unix as
$ABC="select * from table"
I want to pass the variable name from file and use the variable in script with the value in script.
so I need to run script like
for i in /path/file_config;
$Variable=ABC
echo $variable # need result "select* from table"
Please help me in this
Upvotes: 0
Views: 497
Reputation: 49
Adding a slight improvement to Shawn's response above:
for Variable_name in `awk -F: '{ print $1 }' /path/file_config`; do
Variable=$Variable_name
echo ${!Variable}
done
Upvotes: 0
Reputation: 52336
In bash
(But not other shells), ${!foo}
is an indirect reference that expands to the value of the variable named in $foo
.
So,
ABC="select * from table"
name=ABC
echo "${!name}"
will display select * from table
Upvotes: 1