fateame 发表于 2018-8-21 13:38:22

shell case循环写个计算器

  刚学习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

页: [1]
查看完整版本: shell case循环写个计算器