Saturday, June 9, 2018

SHELL SCRIPT TO PERFORM A SIMPLE CALCULATOR

echo "Enter two number"
read x
read y
r=0
echo "1.Addition"
echo "2.Subtruction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
case $ch in
1) r=`expr $x + $y`
   ;;
2) r=`expr $x - $y`
   ;;
3) r=`expr $x \* $y`
   ;;
4) r=`expr $x \/ $y`
   ;;
*) echo "Wrong choice"
esac
echo "Result= $r"

                                                       OUTPUT

biswarup@biswarup-desktop:~$ sh
$ sh calculator.sh
Enter two number
2
3
1.Addition
2.Subtruction
3.Multiplication
4.Division
Enter your choice
2
Result= -1
$

No comments:

Post a Comment