Linux shell script to check if the Number is a Prime or not?

number=53
i=2
flag=0
while test $i -le `expr $number / 2`
do
if test `expr $number % $i` -eq 0
then
flag=1
fi
i=`expr $i + 1`
done

if test $flag eq 1 then echo “The number is Not Prime” else echo “The number is Prime”

fi

Linux Shell script to display prime numbers

echo 'Enter no'
read x
n=2
while [ $n -le $x ]
do
i=2
count=1

while [ $i -lt $n ]
do
if [ `expr $n % $i` -eq 0 ]
then
count=0
break
fi
i=`expr $i + 1`
done

if [ $count -eq 1 ]
then
echo "$n is Prime"
fi

n=`expr $n + 1`
done

Linux shell script to display date, time of the machine:

now=$(date)
echo “$now”
echo “Current date: $now”
echo Current Date and Time is: `date +”%Y-%m-%d %T”`

Linux shell script/commands to find os name and version:

cat /etc/os-release

 

Linux shell script/commands to list processes running:

$ ps 

Linux Shell Scripts

Leave a Reply

Your email address will not be published. Required fields are marked *