0 votes
8 views
in Devops Culture by (2.1k points)
Write a shell script to print only prime numbers?

1 Answer

0 votes
by (1.5k points)

prime.sh

echo "1"

i=3

j=300

flag=0

tem=2

echo "1"while [ $i -ne $j ]

do

        temp=`echo $i`

        while [ $temp -ne $tem ]

        do

                temp=`expr $temp - 1`

                n=`expr $i % $temp`

                if [ $n -eq 0 -a $flag -eq 0 ]

                then

                        flag=1

                fi

        done

        if [ $flag -eq 0 ]

        then

                echo $i

        else

                flag=0

        fi

        i=`expr $i + 1`

done

Related questions

0 votes
1 answer
7 views
0 votes
1 answer
5 views
0 votes
1 answer
10 views
0 votes
1 answer
11 views
0 votes
1 answer
9 views
...