Programming Tutorials

Calculator tutorial in Shell Script

By: Vivek G in Linux Tutorials on 2011-01-29  

This shell script shows a simple calculator application.
   if test $# = 3
then
	case $2 in
	 +) let z=$1+$3;;
	 -) let z=$1-$3;;
	 /) let z=$1/$3;;
	 x|X) let z=$1*$3;;
	 *) echo Warning - $2 invalied operator, only +,-,x,/ operator allowed
	    exit;;
	esac
	echo Answer is $z
else
	echo "Usage - $0   value1  operator value2"
	echo "        Where, value1 and value2 are numeric values"
	echo "               operator can be +,-,/,x (For Multiplication)"
fi





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Linux )

Latest Articles (in Linux)