Shell Script to Create a Simple Calculator - The Coding Shala

Home >> Scripting >> simple calculator

Shell Script to Create a Simple Calculator

Write a shell script to create a simple calculator using a switch-case statement?


echo "simple calculator"
echo "enter first number"
read n1
echo "enter second number"
read n2
while [ $i = "y" ]
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter choice"
read ch
case $ch in
1)sum=$(echo " $n1 + $n2" | bc -l)
echo "Addition is =" $sum;;
2)sum=$(echo "$n1 - $n2" | bc -l)
echo "Sub is =" $sum;;
3)sum=$(echo "$n1 * $n2" | bc -l)
echo "Mul is =" $sum;;
4)sum=$(echo "$n1 / $n2" | bc -l)
echo "div is =" $sum;;
*)echo "invalid choice"
echo "Do you want to continue"
read i
if [ $i != "y" ]

Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.


  1. in the program when we opt to continue its taking the same number as we had given in the starting and it is asking for only operations.....we are not getting the chance to give new inputss


Post a Comment

Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Single Number 3 LeetCode Solution - The Coding Shala

LeetCode - Number of Good Pairs Solution - The Coding Shala

Java Method Overloading - The Coding Shala