Menu Driven Shell Program to Perform Following Functions
1. Greatest of 3 nos
2. Reverse a no
3. Sum of 4 digit no
4. Accept a word & no 'n'.Print word 'n' times.
*********************************************************************************
echo "1.Greatest of 3 nos"
echo "2.Reverse a no"
echo "3.Sum of 4 digit no"
echo "4.Accept a word & no 'n'.Print word 'n' times."
echo "Enter ur Choice::"
read choice
case "$choice" in
1)
echo "Enter Three Nos::"
read n1 n2 n3
echo -e "\nGreatest no is::"
if [ $n1 -gt $n2 -a $n1 -gt $n3 ]
then
echo $n1
elif [ $n2 -gt $n1 -a $n2 -gt $n1 ]
then
echo $n2
else
echo $n3
fi
;;
2)
echo "Enter a no::"
read n
on=$n
rev=""
while [ $n -gt 0 ]
do
s=`expr $n % 10`
n=`expr $n / 10`
rev=$( echo $rev$s)
done
echo "$on is reversed to $rev"
;;
3)
echo -e "Enter a no::"
read n
sum=0
while [ $n -gt 0 ]
do
s=`expr $n % 10`
n=`expr $n / 10`
sum=`expr $sum + $s`
done
echo "Sum of digits of no is $sum"
;;
4)
echo -e "Enter a Word::"
read word
echo -e "Enter a No::"
read n
i=1
while [ $n -gt 0 ]
do
n=`expr $n - 1`
echo $i ")" $word
i=`expr $i + 1`
done
;;
esac
echo "2.Reverse a no"
echo "3.Sum of 4 digit no"
echo "4.Accept a word & no 'n'.Print word 'n' times."
echo "Enter ur Choice::"
read choice
case "$choice" in
1)
echo "Enter Three Nos::"
read n1 n2 n3
echo -e "\nGreatest no is::"
if [ $n1 -gt $n2 -a $n1 -gt $n3 ]
then
echo $n1
elif [ $n2 -gt $n1 -a $n2 -gt $n1 ]
then
echo $n2
else
echo $n3
fi
;;
2)
echo "Enter a no::"
read n
on=$n
rev=""
while [ $n -gt 0 ]
do
s=`expr $n % 10`
n=`expr $n / 10`
rev=$( echo $rev$s)
done
echo "$on is reversed to $rev"
;;
3)
echo -e "Enter a no::"
read n
sum=0
while [ $n -gt 0 ]
do
s=`expr $n % 10`
n=`expr $n / 10`
sum=`expr $sum + $s`
done
echo "Sum of digits of no is $sum"
;;
4)
echo -e "Enter a Word::"
read word
echo -e "Enter a No::"
read n
i=1
while [ $n -gt 0 ]
do
n=`expr $n - 1`
echo $i ")" $word
i=`expr $i + 1`
done
;;
esac