
菜鳥請教shell編程問題 case if else
#用一個whileloop直到不想玩while:#
#-p”pleaseinputthefirstnumber(or’q’toquit):”first_numshell編程菜鳥教程。
if[“$first_num”==”q”]
then
echo”bye!”linux shell 菜鳥教程。
exit批處理教程 菜鳥教程。
else
#checkiftheinputisalldigits
re=’^[0-9] $’
if![[$first_num=~$re]]shell腳本在線運行。
then
echo”first_numisnon-numeric,重來!”
continuefi#-p”pleaseinputthesecondnumber(or’q’toquit):”second_num
if[“$second_num”==”q”]
thenshell在線編程網站。

echo”bye!”
exit
else
#checkiftheinputisalldigits
re=’^[0-9] $’常用shell腳本。
if![[$second_num=~$re]]ssh命令。
then
echo”second_numisnon-numeric,重來!”
continuefi#askusertoentertheoperator( ,-,*,/)read-p”pleaseenter運算符號( ,-,*,/):”operatorshell腳本基礎教程。
case$operator’ ‘)letresult=$first_num $second_num
echo”$first_num $second_num=”$result你可以自己做這些事情*#這些你可以自己做‘/’#這些你可以自己做*)#anythingelseisinvalid
echo”Invalidoperator,pleaseenter’ *tryagain!”esac
done