歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

shell腳本實現算術運算且輸入的不能為非數字的數,shell算術

shell腳本實現算術運算且輸入的不能為非數字的數,shell算術

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

 

http://xxxxxx/Linuxjc/1176186.html TechArticle

Copyright © Linux教程網 All Rights Reserved