why is it workin for 1 file , but not for multiple files?

Hi , this peice of code is working for one file but not for multiple files.
Can some one please tell me the reason???

for i in `ls -1 | egrep ''SOM.*` ; do
filename=$(ls -1 $i)
filename=$(print $filename)
if [[ $filename = '.pat' ]]
then
print "Skipping file $i since it already has a .patextension\n"
else
print "Testing file $i"
last_line=$(tail -1 $i)
last_line=$(print $last_line)
if [[ $last_line = 'FOOTER'
]]
then
print "Proper end of file detected"
print "Appending $i with .pat extension\n"
mv $i $i.pat
else
print "Proper end of file NOT detected - aborting load....\n"
fi
fi
done

Its appending .pat when only one file is there in the directory,but its failing for other files...

Sorry, i couldn't figure out.Please tell us what is the problem that you are attempting to solve.

Thanks
Nagarajan G