dsravan
September 13, 2006, 10:27am
1
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.
myfilepattern=$1_$2
fullpattern=${myfilepattern}_$NEW_DT.dat
integer filecount=0
for file in $fullpattern ; do
[ "$file" != "$fullpattern" ] && filecount=$filecount+1
done
if (( $filecount == 1 )); then
I pass 2 parameters to the script.
and the debug output shows it;s reading 2 times in the for loop.
vino
September 13, 2006, 10:53am
2
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
anbu23
September 13, 2006, 11:01am
3
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
dsravan
September 13, 2006, 11:23am
4
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.
myfilepattern=$1_$2
fullpattern=${myfilepattern}_$NEW_DT.dat
integer filecount=0
for file in $fullpattern ; do
[ "$file" != "$fullpattern" ] && filecount=$filecount+1
done
if (( $filecount == 1 )); then
Please observer that there is no space in fullpattern variable here. Please suggest
anbu23
September 13, 2006, 11:36am
5
check this variable NEW_DT contains any space. if you have still problem show us how did you get the value for that variable
dsravan
September 13, 2006, 12:07pm
6
Thanks Anbu, the NEW_DT is having space in it. It solved the problem.
Thanks,