Declaring variable with another variable

Hi All,

The issue is that for changing name of the file i'm writing a script, there the at one point i need to declare a variable some thing like 'var1, var2, var3 ......' which has to store some value.

Script as follows:

for i in `echo xxxx_dddd_ccc_plsql_zz.sql |tr "_" ' '`
do
  count=`expr $count + 1`
  var`echo $count`=$i      -------> this step not working
  echo "$var`echo $count`"  ---------> echo is working for only 'count' variable 
done

Result:

./2test.sh[8]: var1=update:  not found.
1
./2test.sh[8]: var2=adjustable:  not found.
2
./2test.sh[8]: var3=ccc:  not found.
3
./2test.sh[8]: var4=plsql:  not found.
4
./2test.sh[8]: var5=zz.sql:  not found.
5

Haven been breaking my head from 2days :wall:, please help in this regard.
Thanks in advance :slight_smile:

Can you try as below and check..?

for i in `echo xxxx_dddd_ccc_plsql_zz.sql |tr "_" ' '`
do
	count=`expr $count + 1`
	eval var${count}=${i}
	eval echo \$var${count}
done

Hi Michael,

thanks for the help its working fine :):):slight_smile:

:b::b: