Nonsense not much to say, directly on the code, the basic implementation of subtraction functions:
#!/bin/bash# author by alsww# date : 2016.02.03# mail : [email protected]# blog : alsww.blog.51cto.comprint_info () { printf " Please enter the number: \ n "}print_err_num () { printf " Please enter the correct number!\n "}print_err_fuhao () { printf "Please enter the correct operation symbol (+ - * /): \ n"}while :d O read -p "Please enter the first digit:" num1 echo $num 1|grep -q ' ^[-]\? [0-9]\+$ ' && break | | print_err_numdonewhile :d o read -p "Please enter an operator (shaped like :+ - * /): " ysf if [ " $YSF " != " + " ]&&[ "$YSF" != "-" ]&&[ "$YSF" != "*" ]&&[ "$YSF" != "/" ] then print_err_fuhao else break fidonewhile :d o read -p "Please enter the second digit:" num2 echo $num 2|grep -q ' ^[-]\? [0-9]\+$ ' && break | | print_err_numdoneecho "Operation Result: ${num1}${ysf}${num2}=$ ((${num1}${ysf}${num2})) "
Effect:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7A/B8/wKioL1axxFGT4VIGAAAlxmPm3J0690.png "title=" Qq20160203170931.png "alt=" Wkiol1axxfgt4vigaaalxmpm3j0690.png "/>
This article is from the "bitter coffee ' s Yun ' an Road" blog, please be sure to keep this source http://alsww.blog.51cto.com/2001924/1740963
Shell implementation of a simple calculator function small script