首页 > 代码库 > shell脚本实现算术运算且输入的不能为非数字的数

shell脚本实现算术运算且输入的不能为非数字的数

#!/bin/bash
echo "请输入第一个数"
read a
echo "请输入第二个输"
read b

if [[ ${b} != *[!0]* ]] && [[ ${a} != *[!0123456789]* ]];

then
echo "除数为0!!!!!!!!!!!!!!!!!"
echo "和为"`echo $(( ${a} + ${b} ))`
echo "差为"`echo $(( ${a} - ${b} ))`
echo "积为"`echo $(( ${a} * ${b}))`

elif [[ ${a} != *[!0123456789]* ]] && [[ ${b} != *[!0123456789]* ]];

then
echo "和为"`echo $(( ${a} + ${b} ))`
echo "差为"`echo $(( ${a} - ${b} ))`
echo "商为"`echo $(( ${a} / ${b} ))`
echo "积为"`echo $(( ${a} * ${b}))`
echo "余数为"`echo  $(( ${a} % ${b}))`


else

echo "输入错误"

fi

 

shell脚本实现算术运算且输入的不能为非数字的数