Not able to exit from case statements

Hi all,

I wrote the following simple shell script to perform addition, subtraction, multiplication and division. In the below program, i am not able to exit from the script

Shell Script
-----------

#!/bin/sh
bgcal() {
cal=""
echo "Enter the Option Number: \c"
read cal
if [ $cal = 1 ]
then
echo "You have selected addition"
elif [ $cal = 2 ]
then
echo "You have selected subtraction"
elif [ $cal = 3 ]
then
echo "You have selected multiplication"
elif [ $cal = 4 ]
then
echo "You have selected division"
else
echo "selection invalid. Please choose between 1-4"
fi
case $cal
in
1) echo "Enter two numbers for addition"
   read a b
   c=`expr $a + $b`
   echo " Addition of $a + $b is $c"
   echo " Do you want to continue"
   read ans
   if [ ans -eq 'yes' ]
   then
   bgcal
   else
   exit 0
   fi;;
2) echo "Enter two numbers for subtraction"
   read a b
   c=`expr $a - $b`
   echo " Subtraction of $a - $b is $c"
   echo " Do you want to continue"
   read ans
   if [ ans -eq 'yes' ]
   then
   bgcal
   else
   exit 0
   fi;;
3) echo "Enter two numbers for multiplication"
   read a b
   c=`expr $a \* $b`
   echo "Multiplication of $a * $b is $c"
   echo " Do you want to continue"
   read ans
   if [ ans -eq 'yes' ]
   then
   bgcal
   else
   exit 0 
   fi;;
4) echo "Enter two numbers for Division"
   read a b
   c=`expr $a / $b`
   echo "Division of $a / $b is $c"
   echo " Do you want to continue"
   read ans
   if [ ans -eq 'yes' ]
   then
   bgcal
   else
   exit 0
   fi;; 
*) echo "Do you want to continue?"
    read opt
     if [ opt -eq "yes" ]
     then
      bgcal
     else
     exit 0
     fi;;
esac
 }
echo "Choose the type of operation"
echo "============================"
echo "1-Addition"
echo "2-Subtraction"
echo "3-Multiplication"
echo "4-Division"
bgcal

Output:

> ./t2.sh
Choose the type of operation

1-Addition
2-Subtraction
3-Multiplication
4-Division
Enter the Option Number: 1
You have selected addition
Enter two numbers for addition
4 5
Addition of 4 + 5 is 9
Do you want to continue
no
Enter the Option Number: 2
You have selected subtraction
Enter two numbers for subtraction
5 3
Subtraction of 5 - 3 is 2
Do you want to continue
no
Enter the Option Number:

Kindly let me know where i am wrong.

Thanks in advance

Hi,
Change this

read ans
   if [ ans -eq 'yes' ]

with:

read ans
  if [ $ans = 'yes' ]

Even

if [ opt -eq "yes" ]

should be

if [ $opt =  "yes" ]

Make sure that variables always should have "$" as prefix when used in any expressions.

Thank you ripat and panyam. It works perfectly fine