Reputation: 722
let's say we have a properties file: myprops.properties
with the following key pair values:
In my script I wrote these lines:
_ENVIRONMENT="test"
. myprops.properties # load the properties
I would like to access the user property starting with $_ENVIRONMENT i.e."test"
_USER=$_ENVIRONMENT"_user" # this does not work it outputs "testuser" which is the key and not the value.
If I declare:
echo ${testuser} # that works I get the value
What I am missing? Is it possible?
Thanks in advance,
Upvotes: 1
Views: 43
Reputation: 785611
You can use indirect variable reference:
varUser="${_ENVIRONMENT}_user"
echo "${!varUser}"
myuser
Upvotes: 2