Error in Loop?

hi friends,
i wrote one simple shell script.. in that am using for loop... when i am trying to execute the script[ksh-x filename].it shows syntax error at for loop line '((' unexpected.

#!/bin/ksh
##
##### To find no of files in the directory

NOF=`ls -l /root/COMM/LOGS/eds/20081025| wc -l`
if [ $NOF -ne 0 ]
then
 NOF=`expr $NOF - 1`
fi
OUTFILE= /root/temp/checking/outputfile
#OUTFILE= /root/temp/checking/outputfile
echo " /root/COMM/LOGS/eds/20081025 no of files is  ${NOF} " > $OUTFILE

if [ $NOF -ne 0 ]
then
  for ((i=1; $i<=`cat /root/temp/checking/address.txt|wc -l`; i++ ))
  do
    TO=`head -$i /root/temp/checking/address.txt | tail -1`
    MFILE=/root/temp/checking/mailfile
    echo "From: "Gnanaprakasam" <gnanaprakasam@xyz.com>" > $MFILE
    echo "To: ${TO}" >> $MFILE
    echo "Date: `date`" >> $MFILE
    echo "Subject: due to the script execution problem " >> $MFILE
    echo -e "\n\n" >> $MFILE
    echo "Dear Sir/Madam," >> $MFILE
    echo -e "\n\t Due to the script execution problem the following file are created" >> $MFILE
    echo -e  "\n\n `ls -lt /root/COMM/LOGS/eds/20081025 | tr -s " " | cut -f 6,7,8,9 -d " "`" >> $MFILE
    echo -e  "\n" >> $MFILE
    ##/bin/cat $MFILE |  /usr/sbin/sendmail -fgnanaprakasam@xyz.com $TO
    sleep 2
  done
fi

Hi prakasam,

The syntax for for is wrong... its for i in 1,2,3 ect...

Regards,
Bips... :b:

looks like he put the for loop from "C" :smiley:

As-is, this code worked on my Linux system using pd-ksh. Further, that for-loop works in zsh, ksh, and bash. The $ before the i in the loop condition is not necessary, but it does not harm anything either. The cat|wc -l should work fine, but this is evaluated every iteration and so it should be done like this:

maxlines=`cat ...|wc -l`
for ((i=0; i <= maxlines; i++)) 

It could be your ksh is broken, or very old, or mine implements non-standard features.

thanks friens its working now

in the same prgm echo -e "\n\n `ls -lt /root/COMM/LOGS/eds/20081025 | tr -s " " | cut -f 6,7,8,9 -d " "`" >> $MFILE
is not working properly in KSH ... i tried so many times... can any one help me ?
Thanks in advance