Shell编程简单实现四则运算
Shell编程简单实现四则运算:
- #!/bin/sh
- main()
- {
- echo "#############################"
- echo "## usage: num1 +/-/#// num2##"
- echo "## example: 1 + 1 ##"
- echo "## '*' is replaced by '#' ##"
- echo "#############################"
- while [ 1 ]
- do
- echo "## please select : ##"
- echo "## 1.cal ##"
- echo "## 0.exit ##"
- read select
- if [ "$select" = "1" ]
- then
- cal;
- elif [ "$select" = "0" ]
- then
- break;
- fi
- done
- }
- cal()
- {
- echo "please enter number,as: number1 sign number2:"
- read str
- num1=`echo $str|cut -d' ' -f1`
- num2=`echo $str|cut -d' ' -f3`
- sign=`echo $str|cut -d' ' -f2`
- case $sign in
- +)
- sum=`expr $num1 + $num2`;
- echo "$num1 $sign $num2 = $sum";;
- -)
- sum=`expr $num1 - $num2`;
- echo "$num1 $sign $num2 = $sum";;
- \#)
- sum=`expr $num1 \* $num2`;
- echo "$num1 * $num2 = $sum";;
- /)
- sum=`expr $num1 / $num2`;
- echo "$num1 $sign $num2 = $sum";;
- *)
- echo "your enter is wrong";;
- esac
- echo "please enter to continue"
- read cto
- }
- main
相关推荐
zhiliang 2020-01-31
roseying 2019-12-01
帕尼尼 2014-01-13
星愿 2019-11-16
85397518 2019-11-16
getianao 2019-11-16
yboker 2019-06-30
hyv 2014-01-13
袁萌 2017-10-01
xiaohao 2011-04-06
drilistbox 2019-04-25
pythoncream 2016-02-27
LHpython 2019-04-08
吴家应 2014-03-10
PHP100 2019-03-28
PHP100 2019-03-27
明学的白板 2018-05-20
锦妖和她的小伙伴们 2018-04-19