```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 ``` ```#!/usr/bin/env bash USAGE="\$(basename \$0) \n \n \t Print all prime numbers between the two specified numbers. \n \n \t Options \n \n \t\t [-h|--help]\t\t\t This message gets printed only. \n \t\t [-n|--min] \t The start number, inclusive. \n \t\t [-m|--max] \t The end number, inclusive. \n " args=`getopt -o "hn:m:" -l "help,min,max" -- "\$@"` eval set -- "\$args" while true; do case "\$1" in -h | --help) echo -e \${USAGE}; exit;; -n | --min) shift; min="\$1"; shift;; -m | --max) shift; max="\$1"; shift;; --) shift; break;; *) echo "Internal error!"; exit 1;; esac done if [[ \${min}%2 -eq 0 ]]; then min=\$((\${min} + 1)) fi total=0 first_prime=2 second_prime=3 for ((i=\${min}; i<=\${max};)); do sqrt_of_i=\$(echo "sqrt(\$i)" | bc -l) sqrt_of_i=\${sqrt_of_i%.*} is_prime=true for ((j=\${second_prime}; j<=\${sqrt_of_i};)); do if [[ \${i}%\$j -eq 0 && \$i -ne \$j ]]; then #echo prime=false i=\$i j=\$j is_prime=false break fi j=\$((\$j + \${first_prime})) done if [[ \$is_prime == true ]]; then #echo is_prime=\$is_prime total=\$((\$total+1)) #echo \$i fi i=\$((\$i + \${first_prime})) done echo "Total primes: \$total" ```