Advertisement
Shailrshah

Prime Number Check by Command-Line Argument

Aug 11th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.30 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $1 -le 0 ];
  3.         then
  4.         echo "Invalid input. Enter a positive number."
  5.         exit 1
  6. fi
  7. for((i=2; i<$1/2; i++)){
  8.         if [ `expr $1 % $i` -eq 0 ];
  9.                 then
  10.                 echo "$1 is not prime."
  11.                 exit 1
  12.         fi
  13. }
  14. echo "$1 is prime."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement