Prime number finder in bash
Firstly, the algorithm is poor.  Repeated trial division is one of the worst ways to generate primes.  Prefer a sieve of some sort (you can use an array to store the primes).

Instead of true; return we can return 0; similarly, return 1 can replace false; return.

Testing $? is usually a sign that you simply need to move the tested command:

if ! hasFactor $n
then
    echo $n
fi


Or simply:

hasFactor $n || echo $n