首页 > 代码库 > shell脚本结合函数实现简单计算器功能

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脚本结合函数实现简单计算器功能