Advertisement
fueanta

Find Primes in Bash

Aug 26th, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.53 KB | None | 0 0
  1. # straight outta fub
  2.  
  3. printf "Starting Point [SPACE] Ending Point: "
  4. read -r starting ending
  5.  
  6. IsPrime=1
  7.  
  8. while [ $starting -le $ending ]
  9. do
  10.     iteration=2
  11.     IsPrime=1
  12.    
  13.     while [ $iteration -lt $starting ]
  14.     do
  15.         if [ `expr $starting % $iteration` -eq 0 ]
  16.         then
  17.             IsPrime=0
  18.             break
  19.         fi
  20.             iteration=`expr $iteration + 1`
  21.     done
  22.    
  23.     if [ $IsPrime -eq 1 ]
  24.     then
  25.         printf "$starting "
  26.     fi
  27.         starting=`expr $starting + 1`
  28. done
  29. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement