while loop in shell scripting

Hi,
I have a doubt in usage of while loop in Shell script as Iam new to this.

My requirement is that,I have two different directories containing some files which move files to other folder after parsing is done.
In my script i wanted to add a while loop which checks for the count in these two folders and once it is 0 then executes a function else will sleep for sometime until the count equals 0 and then moves on.
Below is the way Iam using:

cd /dir1
ls |wc >> list
c1=$(cut -c 1-8 list
cd /dir2
ls |wc >> list1
c1=$(cut -c 1-8 list1
while [ $c1 -eq 0 && $c1 -eq 0 ]
do
function
sleep 1000
done
}

Is this the correct way of using the while loop?

Regards,
Jyothi

Yes the loop is correct syntax

while [ $x -le 10 ]
do
  echo "You can add your commands"
  x=`expr $x + 1`
done

Yep, I see your loop syntax to be correct. I do have a small sugession for getting number of files in a directory. Below code uses same logic as yours but tuned a little.

c1=`ls /dir1 | wc | cut -c1-8`
c2=`ls /dir2 | wc | cut -c1-8`

your loop is wrong you can't use && as you did;
correction:-

while [ $c1 -eq 0 -a $c1 -eq 0 ]
do
function
sleep 1000
done
}

or
while [ $c1 -eq 0 ] && [ $c1 -eq 0 ]
do
function
sleep 1000
done
}

;);):wink:

Thanks a lot for all ur replies.
Is there a way to change the code for my below requirement?

The code which i specified in the last post has initial count of the files in the dir.But the files get on decreasing after some time and atlast become 0.
But the while loop does not ge executed since the count is never 0 rather it has the initial count.
The loop shld continuously chk for the count and when it is 0 the statements shld be executed.
How will i keep track of the count ie ls = 0 of the dir.

Can someone please help me out soon....

use until instead of while.

look at its usage in the forum old posts

until [ condition ]
do
commands
done