Variable names

Hi

I have several variables called

var1, var2, var3, var4 and so on.

I would like to examine the contents of the variables using a loop

and a variable called num which equals a figure

eg

num=3

I wanted to do something like

echo $var$num

to display the contents of var3

I probably need to use quotes or eval or something but I'm not quite sure how - can anyone help please?

Thanks
Helen:confused:

I think you have to concatenate the $var ans the $num like this

echo $var & $num - but im not sure about this and have no access to a unix box to look after ist - sorry

Frank

dfhname=`echo $file | awk -F. '{ print $1 $2 }'`

eval echo \"\$$dfhname\"

You didn't say which shell -

CSH:

#!/bin/csh -f
set counter = 0
set var = "file"
loop:
@ counter = $counter + 1
echo $var$counter
if ($counter > 5) then
exit
endif
goto loop

KSH:

#!/bin/ksh
counter=0
var="file"
while [ $counter -lt 5 ]
do
counter=$(($counter+1))
echo $var$counter
done

Thanks for your tips everyone. I was able to work it out from your help as follows

eval echo "\$var$num"

This will show the contents of var3

Thanks
Helen:)