I am trying to create a calculator:echo What is your number?read n1 echo what is your second number?read n2echo what do you want to do?echo 1. addecho 2. subtractecho 3. divideecho 4. multiplyread ansif ans=$(( $n1+$n2 )); thenecho $anselifans=$(( $n1-$n2 )); thenecho $anselifans=$(( $n1/$n2 )); thenecho $anselifans=$(( $n1*$n2 )); thenecho $anselseBut when I insert letters it shows me 0.How can I improve it? Also it gives me sometimes wrong answers.
How create calculator in linux script?
shell script;string
Try to use while loop : input=yeswhile [[ $input = yes ]]do    PS3=Press 1 for Addition, 2 for subtraction, 3 for multiplication and 4 for division:     select math in Addition Subtraction Multiplication Division    do        case $math in        Addition)            echo Enter first no:            read num1            echo Enter second no:            read num2            result=`expr $num1 + $num2`            echo Answer: $result            break        ;;        Subtraction)            echo Enter first no:            read num1            echo Enter second no:            read num2            result=`expr $num1 - $num2`            echo Answer: $result            break        ;;        Multiplication)            echo Enter first no:            read num1            echo Enter second no:            read num2            result=`expr $num1 * $num2`            echo Answer: $result            break        ;;        Division)            echo Enter first no:            read num1            echo Enter second no:            read num2            result=$(expr scale=2; $num1/$num2 | bc)            echo Answer = $result            break        ;;        *)            echo Choose 1 to 4 only!!!!            break        ;;    esac    donedone