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
}
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.
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.