I am writing a shell script that has to read a file(dataserver.properties) and alter some properties in it according to its type. I can have 10 different types in total (agis_int,agis_psr....). All of the types share the same number of variables (10 in total). this is an example of a data server.properties file
eg agis_int_dataserver.properties:
ODI_dataserver=< agis_int_dataserver>
ODI_user=< agis_int_host>
ODI_password=< agis_int_password>
ODI_hostname=< agis_int_hostname>
ODI_port=< agis_int_port>
I already have each of those properties loaded in a profile configuration file. Their names are [type]_property like below
.profile_topologies
export agis_int_dataserver=PAM_export
export agis_int_host=192.168.1.17
...
export agis_int_psr=SAM_im
export agis_int_psr=192.168.1.45
I know before hand the type name (one of the 10) and my goal is to kind of do a double parameter/variable substitution? I do not know if such thing exists but I wanted to avoid using a lot of if-cases.
what I wrongly came up with was
#the type parameter has the string name of the type (agis_int, agis_psr...)
func( type) {
eg $type hold the string agis_int
cat $datasource_file | sed "s/<${type}_dataserver>/${${type}_dataserver}/g" >newdatasource.txt
(this one hold string name)<-------| |
|
(would hold variable value in the environment property)<-|
}
In the case above the first ${type}_dataserver expands to "agis_int_dataserver" string corredtly. The second case I would like it to expand to the variable value of "PAM_export" given by the variable agis_int_dataserver=PAM_export.
Is something like this possible, or is there a better way to do this?
I do not know if I made myself clear enough, it is hard to explain.