Reputation: 834
We have below variables declared as such
CONNECT_ERETAIL1="-h17.XXX.XXX.XX1 -uroot -pXXXXXX"
CONNECT_ERETAIL2="-h17.XXX.XXX.XX2 -uroot -pXXXXXX"
ERETAIL_DB1=/usr01/eretail_db1.txt
ERETAIL_DB2=/usr01/eretail_db2.txt
We need to refer them inside for loop
for i in 1 2
do
echo $"CONNECT_ERETAIL""$i"
echo $"ERETAIL_DB""$i"
done
The expected output is :-
-h17.XXX.XXX.XX1 -uroot -pXXXXXX
/usr01/eretail_db1.txt
-h17.XXX.XXX.XX2 -uroot -pXXXXXX
/usr01/eretail_db2.txt
How to achieve this?
Upvotes: 0
Views: 33
Reputation: 4004
This is what you are looking after:
for i in 1 2; do
t1="CONNECT_ERETAIL$i"
t2="ERETAIL_DB$i"
echo "${!t1}"
echo "${!t2}"
done
You can read more about that kind of parameter expansion in this manual.
Also, using all-uppercase variables is discouraged as they may conflict with bash environment variables.
Upvotes: 2