another dumb program written in bash.
I wrote my first bash scrit the other week and am having fun with writting more simple programs. I did another that does math. To anyone who is interested using it or copying it to make you own bash scripts, this is why I posted it. It's a good start to a new script or just to do math.
#!/bin/sh
# calc
# description: A simple bash calculator.
# by micxz [at] hotmail.com
if [ $# -ne 3 ]
then
echo ""
echo " USAGE: calc # [command] #"
echo ""
echo " COMMANDS:"
echo " p or + Plus"
echo " m or - Minus"
echo " t or x Times"
echo " d or / Divided by"
echo " help Displays this list of options."
echo ""
exit 1
fi
case "$2" in
p | +)
let a1=$1+$3
echo ""
echo "$1 Plus $3 = $a1"
echo ""
;;
m | -)
let a2=$1-$3
echo ""
echo "$1 Minus $3 = $a2"
echo ""
;;
t | x)
let a3=$1*$3
echo ""
echo "$1 Times $3 = $a3"
echo ""
;;
d | /)
let a4=$1/$3
echo ""
echo "$1 Divided by $3 = $a4"
echo ""
;;
*)
echo ""
echo " USAGE: calc # [command] #"
echo ""
echo " COMMANDS:"
echo " p or + Plus"
echo " m or - Minus"
echo " t or x Times"
echo " d or / Divided by"
echo " help Displays this list of options."
echo ""
exit 1 ;;
esac
exit 0
Prety dumb, but It works. I did find that trying to use "*" and "t" for times does not work. I could not find a way to escape the '*' .
|