#!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