Why for loop is acting weird

Hey i have a small script in which i check if a file with that pattern exists or not. If present then i go ahead with further processing.

In the present situation i have only one file with that name and for loop is reading twice. Here is the script. And the output of debug mode. Please help.

I pass 2 parameters to the script.

and the debug output shows it;s reading 2 times in the for loop.

Notice the whitespace in
fullpattern=AUD01_CARE_DLY_20060912 .dat

You need to get rid of that space or alternatively use

for file in "$fullpattern" ; do
[ "$file" != "$fullpattern" ] && filecount=$filecount+1
done

AUD01_CARE_DLY_20060912[SPACE].dat
So in for loop it will take as two arguments. If you want to treat as single argument then do this

for file in "$fullpattern" ; do

Thanks friends,

I got it working but i don't understand how the spaces are coming as my code doesn't have any spaces in it.

Please observer that there is no space in fullpattern variable here. Please suggest

check this variable NEW_DT contains any space. if you have still problem show us how did you get the value for that variable

Thanks Anbu, the NEW_DT is having space in it. It solved the problem.

Thanks,