编写一个菜单选择使用加法和乘法运算

#!/bin/bash
#auther:acf


#!/bin/bash
a=$1
b=$2
sum(){
# echo $(($1 + $2))
read -p "first num " num1
read -p "second num " num2
let c=$num1+$num2

}

cf(){
read -p "first num " num1
read -p "second num " num2

let d=$num1*$num2
# let c=$1*$2
# echo $c
#echo cf result $(($1*$2))

}
menu(){
clear
echo -e "1\tsum"
echo -e "2\tcf"
echo -e "3\texit"
echo -e "please key in your choose"
read option

}

main(){

while true
do
menu
case $option in
1)

sum
echo "your first num + second num is $c"
echo "if you want return menu,please input 0 or input another num to out!"
read f
if [ $f == 0 ];then
clear
continue
else break
fi;;


2)
cf
echo "your first num * second num is $d"
echo "if you want return menu,please input 0 or input another num to out!"
read f
if [ $f == 0 ];then
clear
continue
else break
fi;;
3)
break;;

*)

clear
echo "sorry,wrong selection"
;;

esac

done

}
main

posted @ 2015-02-01 16:32  大都比2号  阅读(161)  评论(0编辑  收藏  举报