#!bin/bash
#简易计算器
# Author: tianzhaogao (E-mail: 296862380@qq.coom)
num1=init
num2=init
cal=init
echo "欢迎使用田兆高简易计算器"
read -t 30 -p "num1:" num1
checknum1=$(echo "$num1" | sed 's/[0-9]//g')
while [ -z "$num1" -o -n "$checknum1" ]
do
while [ -z "$num1" ]
do
echo "Error! The inputing can not be empty!"
read -t 30 -p "num1:" num1
checknum1=$(echo "$num1" | sed 's/[0-9]//g')
done
while [ -n "$checknum1" ]
do
echo "Error inputinng! The type of inputing must be int!"
read -t 30 -p "num1:" num1
checknum1=$(echo "$num1" | sed 's/[0-9]//g')
done
done
read -t 30 -p "num2:" num2
checknum2=$(echo "$num2" | sed 's/[0-9]//g')
while [ -z "$num2" -o -n "$checknum2" ]
do
while [ -z "$num2" ]
do
echo "Error! The inputing can not be empty!"
read -t 30 -p "num2:" num2
checknum2=$(echo "$num2" | sed 's/[0-9]//g')
done
while [ -n "$checknum2" ]
do
echo "Error inputinng! The type of inputing must be int!"
read -t 30 -p "num2:" num2
checknum2=$(echo "$num2" | sed 's/[0-9]//g')
done
done
read -t 30 -p "运算符:" cal
checkcal=$(echo "$cal" | sed 's/[\+\-\*\/]//g')
while [ -z "$cal" -o -n "$checkcal" ]
do
while [ -z "$cal" ]
do
echo "Error! The inputing can not be empty!"
read -t 30 -p "运算符:" cal
checkcal=$(echo "$cal" | sed 's/[\+\-\*\/]//g')
done
while [ -n "$checkcal" ]
do
echo "Error inputinng! The type of inputing must be ['+' or '-' or '*' or '/']!"
read -t 30 -p "运算符:" cal
checkcal=$(echo "$cal" | sed 's/[\+\-\*\/]//g')
done
done
if [ "$cal" == "+" ];then
echo "$num1 $cal $num2 = $(($num1+$num2))"
elif [ "$cal" == "-" ];then
echo "$num1 $cal $num2 = $(($num1-$num2))"
elif [ "$cal" == "*" ];then
echo "$num1 $cal $num2 = $(($num1*$num2))"
elif [ "$cal" == "/" ];then
echo "$num1 $cal $num2 = $(($num1/$num2))"
fi
echo "Already completed! Thanks for your using!"
Linux初学者的简易脚本----计算器
最新推荐文章于 2024-05-07 15:27:19 发布