Learning curve to understand bash iteration

Hi Folks,
I know on one side there is script and on another side there is smart script. I am able to achieve what I got but thought there has to be a code which doesn't require multiple lines. So if you guys can help me out than it will be awesome. Also I wrote in cshell but if can get both the cshell and bash version (since I am new to bash) than I will achieve complete success. So task is building up numbers in each iteration, that is first iteration it should look for any file having 1 in it , second it should look for any file having 1,2 and third iteration look for 1,2,3 and so on..here is the code I wrote (not a smart one) which does this:

@ i = 1
while ($i <= 2)
if ($i == 1) then
ls -1d *find*[1]*run*lst
endif
if ($i == 2) then
ls -1d *find*[1,2]*run*lst
endif
@ i++
end

Please help me in this. Once again I can get both csh and bash version that will help in my learning curve to understand bash.
Thank you so much in advance.

Being less familiar with C-shell than other shells, I'm not quite sure I understand what you're doing. So your first loop would look for

filename1.txt

and your second loop would look for

filename1,2.txt

and your third loop would look for

filename1,2,3.txt

are those commas supposed to be in the filename? Or are you expanding the range of filenames you're looking for?

I'm not sure if the kind of meta-substitution you want is possible in the C-shell.

This will work in any bourne shell, including bash, dash, ksh, zsh, ash, and probably others I haven't heard of.

#!/bin/sh

I=1

while [ "$I" -lt 3 ]
do
        RANGE="[1-$I]"

        echo
        echo "Files in range $RANGE"
        echo *${RANGE}* # Will expand to *[0-1]*, etc
        I=`expr $I + 1`
done

sorry for utter confusion. Comas are not in filename, I guess in cshell when you have to look for file filename having 1 or 2 in txt file you can use [1,2] example

ls -1 filename[1,2].txt
 
output
filename1.txt
fielname2.txt
 
ls -1 fielname[1,2,3].txt
 
o/p
filename1.txt
fielname2.txt
fielname3.txt

Thanks

My code ought to do what you want, then.

With a little testing I find you can do nearly the same idea in csh, too. Put the expression you want in a variable, and keep changing it.

#!/bin/sh
# Bourne shell version

I=0

while [ "$I" -le 2 ]
do
        RANGE="[0-$I]"

        echo
        echo "Files in range $RANGE"
        echo *${RANGE}* # Will expand to *[0-1]*, etc

        I=`expr $I + 1`
done
#!/bin/csh
# csh version

@ I = 1
while ($I <= 2)
        set VAR="[0-$I]"

        echo
        echo "Files in range $RANGE"
        echo *${RANGE}*

        @ i++
end

Incidentally -- neither of these program uses arrays, in either language.