Friday, December 2, 2022

Basic calculator in bash script



echo "Enter operation to be performed so that first number operation second number"

read operation

case $operation in

+)

result=`echo "scale=2; $first + $second" | bc`

;;

-)

result=`echo "scale=2; $first - $second" | bc`


;;

\*)

result=`echo "scale=2; $first * $second" | bc`


;;

/)

result=`echo "scale=2; $first / $second" | bc`


;;

*)

result="Not valid"

;;

esac


echo "Result is $result"


No comments:

Post a Comment