Shell program to check the number n is divisible by m or not

Here  m and n are supplied as command line argument or read from key board interactively.

#!/bin/sh
echo "Enter the divident"
read n
echo "Enter the divisor"
read m
y=`expr $n % $m`
if [ $y -eq 0 ]
then
echo " $n is divisible by $m "
else
echo " $n not divisible by $m "
fi
##########################

OUTPUT:

$sh num.sh
Enter the divident
4
Enter the divisor
2
4 is divisible by 2

###############################

Leave a Reply