Iam facing this problem for past 2/3 days. I have a simple script in which i will read a property file and output some of the contents. This is my script
vi testloop.properties
dump_1=abc
vi testloop.sh
. testloop.properties
i=1
dmp="dump_"$i //as per my understanding dmp=dump_1
echo $dump_1 //abc will echod since dump_1 in property file is abc
echo $dmp ***i thought here also abc will come but unfortunately it is "dump_1"***
echo $(($dmp)) ***here output is 0***
sh testloop.sh
abc
dump_1
0
Can some one help me in pointing out what has happend in echo $dmp and echo $(($dmp)) . why it is not echoing abc
dmp="dump_"$iThis assigns the string
"dump_1"rather than the variabledump_1todmp.The other example you gave tries to do arithmetic expansion of
$dmpwhich in this case is just 0.Normally the variable assignment would be
dmp=$dump_1, which is fine, but variable variable assignment, i.e.dmp=$dump_$idoesn’t work as you might hope. You can pass it through anevalstatement like so:eval dmp=\$dump_$1But if you really need variable variables of this nature it might be better to use an array: