From 511c1f2359a60db6bbab1bc28cbdd43668aeac7c Mon Sep 17 00:00:00 2001 From: dee-mee Date: Wed, 3 Apr 2024 08:50:10 +0300 Subject: [PATCH] calculator in bash --- script7.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 script7.sh diff --git a/script7.sh b/script7.sh new file mode 100755 index 0000000..3226128 --- /dev/null +++ b/script7.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +##This script illustrates how to make a calculator using bash + +clear + +sum=0 +i="y" + +echo "Enter first no: " +read n1 +echo "Enter second no: " +read n2 + +while [ $i = "y" ] +do +echo "1. Addition" +echo "2. Subtraction" +echo "3. Multiplication" +echo "4. Division" +read op + +case $op in + 1) sum= expr $n1 + $n2 + echo "sum = "$sum;; + 2) sum= expr $n1 - $n2 + echo "Sub = "$sum;; + 3) sum= expr $n1 \* $n2 + echo "Mult = "$sum;; + 4) sum= expr $n1 / $n2 + echo "Div = "$sum;; + *)echo "Invalid choice";; + +esac + +echo "Do you want to continue (Y/n))? " +read i +if [ $i != "y" ] +then + exit +fi +done