problems calling out variables in a loop

good afternoon forums.
i have a problem that ive been trying to work out all morning and cant seem to get my head around it.
what i have in my script is individual letters saved in different variables. so if the word unix was saved then 'u' would be stored in the variable 'wvar1' 'n' in 'wvar2' 'i' in 'wvar3' and x in 'wvar4'.
what i want to do is loop through each of these to see wether an inputed letter 'in1' is the same as what is in each variable, one at a time. I have come up with the following script.

1)for (( i = 0; i <= 4; i++ ))
2)do
3)rdm=$(($rdm + 1))
4)testvar=$(eval echo $wvar$rdm)
5)if [[ $in1 = $testvar ]]
6)then
7)eval xnum$rdm=$in1
8)fi

1-makes the code loop 4 times
3-adds 1 to the variable rdm each time it loops around
4-testvariable changes each time it goes through the loop to be equal to wvar1 the first time it loops, wvar2 for the second time etc...
5-if the inputed character is equal to the saved variable then do the next command
7-creates a new variable which is equal to the inputed character

I hope i explained my problem well enough for some genius to figure out whats wrong with it. I have been on this same problem for a day and a half now...

This might be or not a nice exercise but why don't you just compare the entered string with a string stored in a variable instead of cycling through every letter?

how would i go about doing that then?

if a word is stored in the variable 'word'?

Your loop is not looping 4 times, it will do 5 times.

the number of times it loops wont really affect the outcome that i am getting, which now i have realised i forgot to put into the first post.

when i echo out what is in the xnum variables i get a number 1 in the first one, 2 in the second one and so on.

this is not what i was expecting to get as an output

Where are you changing the xnum...somehow I am unable to understand your problem...sorry.

in line 7 i do this

7)eval xnum$rdm=$in1

what i want that to do is create a variable xnum1 for the first time the loop hapens, then the second time xnum2.

Can you give us what is the value of each and every variable before the for loop starts...
You if-else statement might not be allowing xnum to execute...
Give detailed requirement.

---------- Post updated at 05:36 PM ---------- Previous update was at 05:36 PM ----------

Also try to run the program with
set -x
so that you can debug.