shell脚本结合函数实现简单计算器功能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本结合函数实现简单计算器功能相关的知识,希望对你有一定的参考价值。
#!/bin/bash
function tool_menu()
{
echo "****************************************************"
echo "* *"
echo "* calculation tools *"
echo "* *"
echo "****************************************************"
}
function menu_choice()
{
echo "A: Add two num."
echo "B: Minus two num."
echo "C: Multiply two num."
echo "D:Divide two num."
echo "Q: Close this function."
echo "Please input your chiose:"
}
function add_num()
{
echo "add."
# echo "please input your number"
# read a
# echo "please input your number"
# read b
let c=$a+$b
echo "$a+$b is:$c"
}
function minus_num()
{
echo "minus."
# echo "please input your number"
# read a
# echo "please input your number"
# read b
let c=$a-$b
echo "$a-$b is:$c"
}
function multiply_num()
{
echo "multiply."
# echo "please input your number"
# read a
# echo "please input your number"
# read b
let c=$a*$b
echo "$a*$b is:$c"
}
function divide_num()
{
echo "divide."
# echo "please input your number"
# read a
# echo "please input your number"
# read b
let c=$a/$b
echo "$a/$b is:$c"
}
function main()
{
clear
tool_menu
while :
do
menu_choice
read menu_choice
read a
read b
case $menu_choice in
A|a) add_num $a $b;;
B|b) minus_num ;;
C|c) multiply_num ;;
D|d) divide_num ;;
Q|q) break;;
*) "error";;
#read a
#read b
#add_num $a $b
esac
# minus_num $a $b
# multiply_num $a $b
# devide_num $a $b
done
}
main
exit 0
92,1 底端
本文出自 “12146768” 博客,请务必保留此出处http://12156768.blog.51cto.com/12146768/1872211
以上是关于shell脚本结合函数实现简单计算器功能的主要内容,如果未能解决你的问题,请参考以下文章
在Linux下,用shell编写一个简单的计算器,要实现加减乘除4个功能就行了