What is the value of count going into the loop?
What shell are you using?
If you add this line into your code, it might show you more detail about what is going wrong:-
set -x
With ksh as my shell, the syntax count=$[$count+1] doesn't give a numeric output, and so the while loop fails with a syntax error. It works fine in bash though.
Okay, no problem. What output do you get from printf $SHELL ?
I expect it will say bash but it's best to check.
You could probably get away with running this for any shell:-
$SHELL -x your_script
You should see a more explicit running of you code including many of the values being set or tested. It could be quite large, but the last block of lines before the failure will be where the interesting bit will be. Is the overall script quite large or can you post it (in CODE tags)