Loop check

Hi Gurus
I have a recquirement where my loop should work if i have more than 4 listed files in a particular directory.
Like the loop in while should continue checking if the directory has more than 4 files and should exit after there are 4 or more files ; if not more than 4 files it should continue checking the number of files

Need help for achieving this scenario

cd /export/home/e299821/rohan
linecount=`ls -ltr | wc -l`
a=0
echo $linecount
echo $a
while [[ $a = 0 ]]
do
if [ $linecount -gt 3 ]
then
echo $lineocunt
a=`expr $a + 1`
echo "loop completed"
fi
done

Are you looking for something like this:

while [ $(ls -1|wc -l) -lt 5 ]
do
        echo 'in loop'
done
echo 'out loop'

this loop shall execute only 4 or max 5 times ... i want that my loop should do the following

varA = 4
varB=8

while [[ varA -ne varB]]
do
check for value of varA till both are equal .
if equal " loop complete " exit
done

r_t_1601, I couldnt understand your requirement. You want a while loop to poll in a directory to check if the folder has more than 4 files and if yes the loop.

Isnt my code doing that?

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

The while condition will compare, why you need both if and while?