Just add a counter variable equal to 5. Decrement by 1 if condition is true, reset to 5 if false, break if count=0. The most trivial answer based on your code:
switchback(){
count=5
while true
do
players=$(cat $serverpath/$port//count.txt);
if (( $players < 10 ));then
if ! ((--count)); then
$(loadpubserveripip)
break
fi
else
count=5
fi
sleep 5
done
}
Few notes:
- I moved the
sleep 5 to the bottom of the loop, to avoid unnecessary sleep at the last loop.
- The "further operation" could be moved from before the
break to after the loop, since the loop will only break the 5th time $players is less than 10.
- I hope you know what your doing with the
$(loadpubserveripip) line, the result of loadpubserveripip should be a valid shell command for it to work.