### Start counting here COUNT=4999 FOUND=0 ### We are looking for the absense of the search string in the UID file ### Once this grep misses, $FOUND becomes empty, and the loop finishes while [ $FOUND ] do let "COUNT += 1" FOUND=`egrep "^$COUNT$" $UID_FILE` done echo "Found unused UID $COUNT"