A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script that sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.
In this post, we will write a shell script to print all Prime Numbers Between n and m.
INPUT:
line 1: n and m
OUTPUT:
prime numbers
The following is the shell script to print all Prime Numbers Between n and m:
echo enter m and n read m n for a in $(seq $m $n) do k=0 for i in $(seq 2 $(expr $a - 1)) do if [ $(expr $a % $i) -eq 0 ] then k=1 break fi done if [ $k -eq 0 ] then echo $a fi done
OUTPUT:
$ enter m and n $ 3 10 $ 3 $ 5 $ 7
Let us know in the comments if you are having any questions regarding this shell script.
And if you found this post helpful, then please help us by sharing this post with your friends. Thank You
That’s Good
very good
Or replace everything after read with `seq 2 100 | factor | sed ‘/ .* / d ; s/:.*//’`. Source: Commandlinefu.
/what are the variables “k” stands for? and what is the number 2 after seq? thanks