Write A Shell Script To Verify The Given Number Is Prime

To verify that the given number is prime.
Linux Bash Shell script Source code Programming In Rhel5
#Shell Script to verify prime no
tput clear
i=2
rem=1
echo "Enter a number:"
read num
if [ $num -lt 2 ]; then
echo "$num is not prime\n"
exit 0
fi
while [ $i -le ` expr $num / 2 ` -a $rem -ne 0 ]; do
rem=`expr $num % $i`
i=`expr $i + 1`
done
if [ $rem -ne 0 ]; then
echo "$num is prime\n"
else
echo "$num is not prime\n"
fi
Bash Shell Script Output
Enter a number:
8
8 is not prime\n
Enter a number:
2
2 is prime\n
CONCLUSION: The following shell script verifies whether the given number is prime or not.

Related post