Write a simple computer using the shell

Source: Internet
Author: User

This is a computer written by the shell, support add, subtract, multiply, divide, take the mold, and provide user input content detection, share to everyone.

#!/bin/bash     #这是一个计算器!     read -p  "Please enter the first number:"  -t 30 num1    read  -p  "Please enter the second number:"  -t 30 num2    read -p  "Please enter the operation symbol (support   + - * / %): " -t 30 op    if [ -n " $num 1 "  -a -n  "$num 2"  -a -n  "$op"  ]    then     n1=$ (echo  $num 1 | sed  ' s/[0-9]//g ')     n2=$ (echo  $num 2  | sed  ' s/[0-9]//g ')     if [ -z  "$n 1"  -a -z  " $n 2 " ]    then    case  $op  in       "+")     r=$ (($num 1 +  $num 2)     ;;      "-")     r=$ (($num 1 -  $num 2)     ;;     "*")     r=$ (($num 1 *  $num 2))     ;;      "/")     r=$ (($num 1 /  $num 2)     ;;      "%")     r=$ (($num 1 %  $num 2))     ;;     *)     echo  "Please enter the correct operator!" "    exit 10    ;;     esac    else    echo  "Please enter the correct number!" "    exit 11    fi    else     echo  "Please enter the correct content!" "    exit 12    fi    echo " $num 1$op$ Num2= $R "


Write a simple computer using the shell

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.