Custom Search

Monday, 3 August 2015

Unix script of calculator for addition, subtraction, division and multiplication operation

 
Unix script for small calculator
Here is the a unix script in which we are going to perform multiple operation including addition, subtraction, division and multiplication operation. The script asks the user to enter his choice about what operation they want to perform and based on that the operation is done. It also asks the use the option at the end if they want to perform any other operation or not.

  1 i="y"
  2
  3 while [ $i == "y" ]
  4 do
  5 echo enter first number:
  6 read number1
  7 echo enter second number:
  8 read number2
  9 echo enter the operator
 10 read operator
 11 if [ $operator == "-" ]
 12 then
 13 echo $(( number1 - number2 ))
 14 elif [ $operator == "+" ]
 15 then
 16 echo $((number1 + number2))
 17 elif [$operator == "*"]
 18 then
 19 echo $((number1 * number2))
 20
 21 elif [$operator == "%"]
 22 then
 23 echo $((number1 % number2))
 24 fi
 25 echo do you want to continue:
 26 read i
 27 if [ $i != "y" ]
 28 then
 29 exit
 30 fi
 31 done

No comments:

Post a Comment

Laptops