初学shell 记录 简单计算器

迷迷茫茫 ,记录 学习

简单的四则运算

#!/bin/bash
#计算器

read -t 30 -p  "Please input the Num1: " num1

read -t 30 -p "Please input the Num2: " num2

read -t 30 -p "Please input the Operater: " ope

sum=0
num11=$(echo $num1 | sed 's/[0-9]//g')
num22=$(echo $num2 | sed 's/[0-9]//g')
ope1=$(echo $ope | sed 's/[A-Za-z0-9]//g')

if [ -z "$num11" -a  -z "$num22" -a -n "$ope1" ]

        then
                case $ope in

                        "+")
                                sum=$(( $num1+$num2 ))
                                echo -e "$sum \n"
                                ;;
                        "-")
                                sum=$(( $num1-$num2 ))
                                echo -e "$sum \n"       
                                ;;
                        "*")
                                sum=$(( num1*num2 ))
                                echo -e "$sum \n"
                                ;;
                        "/")
                                sum=$(( num1/num2 ))
                                echo -e "$sum \n"
                                ;;
                        *)
                                echo "ERROR"
                                ;;
                esac
                exit 1
        else
                echo test 
                exit 2

fi

你可能感兴趣的:(linux学习记录,bash,linux,开发语言)