Simple script----Calculator for Linux Beginners

Source: Internet
Author: User

#!bin/bash# Simple Calculator # author: tianzhaogao  (e-mail: [email protected]) num1=initnum2= initcal=initecho  "Welcome to Tian Shao Simple Calculator" read -t 30 -p  "NUM1:"  num1checknum1=$ (echo  " $num 1 " | sed  ' s/[0-9]//g ') while [ -z " $num 1 " -o -n " $checknum 1 "  ]dowhile [ -z  "$num 1"  ]doecho  "Error! the inputing can not"  be empty! " read -t 30 -p  "NUM1:"  num1checknum1=$ (echo  "$num 1"  | sed  ' s/[0-9] G ') donewhile [ -n  "$checknum 1"  ]doecho  "Error inputinng! the type  of inputing must be int! " read -t 30 -p  "NUM1:"  num1checknum1=$ (echo  "$num 1"  | sed  ' s/[0-9] G ') donedoneread -t 30 -p  "num2:"  num2checknum2=$ (echo  "$num 2"  | sed   ' s/[0-9]//g ') while [ -z  "$num 2"  -o -n  "$checknum 2"  ]dowhile [ -z  "$num 2"  ]doecho  "error! the  inputing can not be empty! " read -t 30 -p  "num2:"  num2checknum2=$ (echo  "$num 2"  | sed  ' s/[0-9] G ') donewhile [ -n  "$checknum 2"   ]doecho  "error inputinng! the  Type of inputing must be int! " read -t 30 -p  "num2:"  num2checknum2=$ (echo  "$num 2"  | sed  ' s/[0-9] G ') donedoneread -t 30 -p  "operator:"  calcheckcal=$ (echo  "$cal"  | sed   ' s/[\+\-\*\/]//g ') while [ -z  "$cal"  -o -n  "$checkcal"  ]dowhile [  -z  "$cal"  ]doecho  "error! the inputing can not be empty!" read -t 30 -p  "Operator:"  calcheckcal=$ (echo  "$cal"  | sed  "s/[\+\-\*\/ ]//g ') donewhile [ -n  "$checkcal"  ]doecho  "error inputinng! the type of inputing " must be [' + '  or  '-'  or  ' * '  or  '/']! ' read -t 30 -p  "Operator:"  calcheckcal=$ (echo  "$cal"  | sed  "s/[\+\-\*\/ ]//g ') donedoneif [  "$cal"  ==  "+"  ];then         echo  $num 1  $cal   $num 2 = $ (($num 1+ $num 2) "elif [ " $cal " ==  "-"  ];then        echo  "$num 1  $cal   $num 2 =  $ (($num 1-$num 2)) "elif [ " $cal " == " * " ];then         echo  $num 1  $cal   $num 2 = $ (($num 1* $num 2) "elif [ " $cal "  ==  "/"  ];then        echo  "$num 1  $cal  $ num2 = $ (($num 1/$num 2)) "fiecho " already completed! thanks for your using! " 


This article is from the "mild feeling Blue Sky" blog, please make sure to keep this source http://tianzhaogao.blog.51cto.com/4716906/1693164

Simple script----Calculator for Linux Beginners

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.