while - comparision

Hi,
Please find the attached scriplet and suggest me to fix the bug in this.
-----------------------------------
noofdirs=`ls *.tar | wc -l`
if [ "$noofdirs" != 0 ] ; then
let i=1
while ( $i <= $noofdirs ) ;
do
echo $i
mkdir $i
file1=`ls *.tar | head -1`
mv $file1 $i
i = `expr $i + 1`
echo $i
done
fi
------------------------------------
I want to create the directory according to tar files. If i 3 tar file, it shuold create 3 directories by the name 1,2 and 3.

Rgds,
Sharif.

Try this:

#!/usr/bin/ksh
noofdirs=`ls *.tar | wc -l`
if ( noofdirs <> 0 )
then
   i=1
   while ( i <= noofdirs )
   do
      echo $i
      mkdir $i
      file1=`ls *.tar | head -1`
      mv $file1 $i
      (( i += 1 ))
      echo $i
   done
fi 
  • I am getting the error 1: not found in the while loop part