≡ Menu

Script to display sum of two number and to do calculations such as +, -, / etc

#!/bin/bash
# Script to display sum of two number and to do calculations such as +, -, / etc
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project 
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
echo "**** My calculator ****"
echo "M A I N - M E N U"
echo "1. Multiplication"
echo "2. Subtraction"
echo "3. Remainder"
echo "4. Divide"
echo -n "Please select your choice (1-4) : "
read choice
echo -n "Enter your first number : "
read n1
echo -n "Enter your second number : "
read n2
if [ $choice -eq 1 ]
then
	answer="$n1 x $n2 = $(( $n1 * $n2 ))"
elif [ $choice -eq 2 ]
then
	answer="$n1 - $n2 = $(( $n1 - $n2 ))"
elif [ $choice -eq 3 ]
then
	answer="$n1 % $n2 = $(( $n1 % $n2 ))"
elif [ $choice -eq 4 ]
then
	answer="$n1 / $n2 = $(( $n1 / $n2 ))"
else
	echo "Sorry please select number between 1-4 only"
	exit 1
fi
echo $answer 
{ 5 comments… add one }
  • Rendy April 29, 2013, 2:16 pm

    why ,if I input -1 + 0.009 = -,991 . Where is these zero??

  • bikash May 6, 2012, 8:22 pm

    this is modular division not division

  • dhruv February 3, 2012, 3:17 am

    hi this is good but i am getting only 0 in division ….

  • Mohamed April 12, 2011, 3:59 am

    Hi ! everything is working fine. Thanks
    but when i try to print * . it prints all the files in the current directory. I am new to Unix so please help me out.
    Thanks :)

  • OPEOLUWA November 13, 2009, 2:04 pm

    THIS REALY IS OF HELP TO ME
    THANKS GUY

Security: Are you a robot or human?

Leave a Comment