Practical no-2
:Shell Script to make a menu driven oprations
clear
sum=0
i="y"
echo
" Enter one no."
read
n1
echo
"Enter second no."
read
n2
while
[ $i = "y" ]
do
echo
"1.Addition"
echo
"2.Subtraction"
echo
"3.Multiplication"
echo
"4.Division"
echo
"Enter your choice"
read
ch
case
$ch in
1)sum=`expr $n1 + $n2`
echo "Sum ="$sum;;
2)sum=`expr $n1 - $n2`
echo "Sub = "$sum;;
3)sum=`expr $n1 \* $n2`
echo "Mul = "$sum;;
4)sum=`expr $n1 / $n2`
echo "Div = "$sum;;
*)echo "Invalid choice";;
esac
echo
"Do u want to continue ?"
read
i
if
[ $i != "y" ]
then
exit
fi
done
OUTPUT
***********
[root
@LINTEL]$ sh calculator.sh
Enter
any no.
121
Enter one no.
21
Enter second no.
58
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
1
Sum =79
Do u want to continue ?
y
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
2
Sub = -37
Do u want to continue ?
y
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
3
Mul = 1218
Do u want to continue ?
y
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
4
Div = 0
Do u want to continue ?
n
No comments:
Post a Comment