variables in shell

hi, i'm new in shell scripting and i'm working on bash on solaris 5.9

after try many stuff with unexpected results, i wonder:
it is not posible in bash, to use a variable that was created inside a loop, out of it?

i mean, for instance:
cat mytext | \
while read text
do
viko[$i]=$text
i=$i+1
done

echo ${viko[1]}
echo $i

those variables, seem to be empty

isn't posible to use any of those (array elements, and $i) outside the loop, before the done statement?

Loops are done as sub-processes. Maybe someone else can give all the details, but if you change from your "cat file" then "do" logic to simply "do" and "done <file" you should be fine.

> cat set_val
#! /bin/bash
# array usage
# do no cat the file to the read, rather do a 
#   while .... done<file

i_ct=0
while read text 
   do
   viko[$i_ct]=$text
   i_ct=$(( i_ct + 1 ))
done <sample.txt

echo ${#viko[*]}
echo ${viko[*]}
echo $i_ct

echo ${viko[1]}

thanks joeyg
that's great

I was trying not to use an external file, but i think this way will work great for me, at least for a while