标签:liunx shell编程 shell乘法 case用法 shell函数的用法 shell使用循环
编写一个shell脚本,实现加法和乘法运算。
#!/bin/bash
#Function:num1+num2 num3*num4
sum(){
read -p "please key in first number:" num1
read -p "please key in second number:" num2
let num3=${num1}+${num2}
echo -e "\033[32m $num1 + $num2 = $num3 \033[0m"
}
#############
cf(){
read -p "please key in first number:" num3
read -p "please key in second number:" num4
let num3=${num3}*${num4}
echo -e "\033[32m $num3 * $num4 = $num3 \033[0m"
}
menu(){
echo "###############calculate#################"
echo -e "1\tsum"
echo -e "2\tcf"
echo -e "3\texit"
read -p "please key in your choose option:" option
}
################
main(){
while [ 1 ]
do
clear
menu
case $option in
1)
sum
echo "Enter any key continue"
read -n 1
clear
;;
2)
cf
echo "Enter any key continue"
read -n 1
clear
;;
3)
exit
;;
*)
echo "输入错误,请重新输入!"
clear
menu
;;
esac
done
}
main;
使用shell脚本实现加法乘法运算,布布扣,bubuko.com
标签:liunx shell编程 shell乘法 case用法 shell函数的用法 shell使用循环
原文地址:http://liyuanji.blog.51cto.com/8671343/1412950