且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

shell case循环写个计算器

更新时间:2022-09-21 22:46:33

刚学习shell的时候,写了一个娱乐的;想起来写在这里,希望大家不要jianxiao!

 #!/bin/bash

echo "先选择运算的种类 加减乘除,然后分别输入运费的数字就可以得到结果,输入时间为30秒"

 

read -p "Please enter the type of operation + or - or * or / :" -t 30 f

 case "$f" in

  "+")

 read -p "Please enter the number1:" -t 30 numb1

 read -p "Please enter the number2:" -t 30 numb2

 typeset -i numb3="$numb1+$numb2"

echo $numb3

 ;;

 "*")

 read -p "Please enter the number1:" -t 30 numb1

 read -p "Please enter the number2:" -t 30 numb2

 typeset -i numb3="$numb1*$numb2"

echo $numb3

;;

"-")

 read -p "Please enter the number1:" -t 30 numb1

 read -p "Please enter the number2:" -t 30 numb2

 typeset -i numb3="$numb1-$numb2"

 

echo $numb3

;;

"/")

 read -p "Please enter the number1:" -t 30 numb1

 read -p "Please enter the number2:" -t 30 numb2

 typeset -i numb3="$numb1/$numb2"

echo $numb3

;;

*)

echo "error,Please re-run!"

esac

 

 

本文转自 houzaicunsky 51CTO博客,原文链接:http://blog.51cto.com/hzcsky/514098