Results 1 to 5 of 5
I have a file consisting of variable definitions like:
Code:
NoOfInstTypes=2
Inst.Type1="Server"
Inst.Type2="Client"
I want to get the value of Inst.Type variables in a loop.
so, I do this
Code:
...
- 10-20-2008 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
getting value of a variable which consists of a variable again like ${${}}
I have a file consisting of variable definitions like:
I want to get the value of Inst.Type variables in a loop.Code:NoOfInstTypes=2 Inst.Type1="Server" Inst.Type2="Client"
so, I do this
But this gives syntax error.Code:NoOfTypes=$NoOfInstTypes while [ $NoOfTypes -ne 0 ] do Type=${Inst.Type$NoOfTypes} .. .. NoOfTypes=`expr $NoOfTypes -1`
- 10-20-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
You might also consider using an array.Code:var1=hello index=1 eval echo \$var$index
- 10-20-2008 #3
burschik's idea might work, but you'll probably also benefit by looking at corrections to your original script.
One of them, you'll notice, is the use of underscores instead of periods.
Hopes this helps.
Code:#!/bin/bash NoOfInstTypes=2 Inst_Type1="Server" Inst_Type2="Client" NoOfTypes=$NoOfInstTypes while [[ $NoOfTypes -ne 0 ]] do Type=Inst_Type$NoOfTypes echo Type is $Type NoOfTypes=$(($NoOfTypes -1)) done
--
Bill
Old age and treachery will overcome youth and skill.
- 10-20-2008 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
You'll need to change:
Type=Inst_Type$NoOfTypes
to:
eval Type=\${Inst_Type$NoOfTypes}
in order to get the value of the variable.
- 10-21-2008 #5
Correct. My bad.
--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote