Shell implementation of a simple calculator function small script

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.