This script will determine all prime numbers between two positive integers a and b. a and b are supplied as command line arguments.
if [ $# -ne 2 ] then echo "Wrong Number of Arguments in the Command Line" exit fi if [ $1 -le 0 -o $2 -le 0 ] then echo "Either 1st or 2nd Argument is NEGATIVE or ZERO " exit fi a=$1;b=$2 if [ $a -gt $b ] then t=$a a=$b b=$t fi i=$a while [ $i -le $b ] do set -- `factor $i | cut -f 2 -d":"` if [ $# -eq 1 ] then echo "$i is a Prime Number" fi i=`expr $i + 1 ` done
$ sh x.sh 2 50 2 is a Prime Number 3 is a Prime Number 5 is a Prime Number 7 is a Prime Number 11 is a Prime Number 13 is a Prime Number 17 is a Prime Number 19 is a Prime Number 23 is a Prime Number 29 is a Prime Number 31 is a Prime Number 37 is a Prime Number 41 is a Prime Number 43 is a Prime Number 47 is a Prime Number