#!/bin/bash
echo "enter your choice :"
echo "1 Addition"
echo "2 subtract"
echo "3 Multiplication"
read er
echo "enter the first number : "
read a
echo "enter the second number : "
read b
if [ $er="1" ]
then
sum=`expr $a + $b`
echo "sum of two numbers is $sum"
elif [ $er="2" ]
then
sub=`expr $a - $b`
echo "the diff of two numbers is $sub"
exit 0
elif [ $er="3" ]
then
mult=`expr $a * $b`
echo "the div of two numbers is $mult"
exit 0
else
echo "invalid choice"
fi
This is a simple script for calculator. But it gets executed only till the first if statement for addition after that it doesn't execute elif statement even if the conditions are true for multiplication and subtraction.
[ $er="1" ]
where say er contains 2 doesn't test if 2 equals 1, it tests if 2=1 is longer than the empty string, and it is. Also if you do/did multiplication your output calls it 'the div' which does not connote multiplication. – dave_thompson_085 Oct 05 '17 at 05:30