You need to decide whether the result of your command is an empty string, not the command it self. Try
while [ -n $(grep -q -F "$username" capstonedata.txt) ]
Edit
A common error is adding an extra dollar sign when you assign values to variables in shell script. Never use anything like
$username=...
if you want to assign something to the variable called username. Remove the dollar sign before it. On the other hand, you need to use i=$i+1
Besides that, I don't really understand what you are trying to achieve by using username=$username[i].
The following script may address your needs or may not, depending on whether I have got your intention right.
#!/bin/bash
(cat <<EOF
$username
EOF
)|(while read line
do
cnt=`grep "\b$line[0-9]*\b" capstonedata.txt| wc -l`
if [ $cnt -gt 1 ]
then
echo $line$cnt
else
echo $line
fi
done
)
Since OP has further clarified his need, the script can be made much simpler.
cnt=`grep "\b$username[0-9]*\b" capstonedata.txt|wc -l`
if [ "$cnt" -eq "0" ]; then
cnt=
fi
username=$username$cnt
Explanation: "$username[0-9]*" matches the $username, with optional digits after it, "\b" matches word boundaries (but this seems to only work with egrep on some systems although it works perfectly fine on my system, you can use grep "\<$username[0-9]*\>" as a safer option) so that you don't accidentally match the line "abcd" when $username is "ab". wc -l counts the number of lines of matches, so if the username has appeared once, the result will be 1. The back-ticks are used to assign the result of a command to a variable, which is in this case $cnt. The if-clause sets $cnt to empty string if it is 0 (i.e. there's no matching in the file). The last line is just appending $cnt to the original user name. So if there is one line that matches the regex the result will be $username with a 1 appended. Precisely what you need.