#!/bin/bash # basic_sieve # The Sieve of Eratosthenes (basic version) M=$1 N=$(echo "scale=0;sqrt($M)+1" | bc) P=( $(seq 2 $M) ) j=0 while test $j -le $N; do if test -n "${P[$j]}"; then k=$j until test $k -gt $M; do let k+=${P[$j]} unset P[$k] done fi let j=$j+1 done echo ${P[*]}