shell 简单计算器

发布时间:2020-07-08 14:28:11 作者:肖武龙
来源:网络 阅读:493

#!/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 "please inut your first num:"
    read first_num
    echo "please inut your second num:"
    read second_num
    let add=$first_num+$second_num
    echo "$first_num+$second_num=$add"
    return 0
}
function minus_num()
{
    echo "please inut your first num:"
    read first_num
    echo "please inut your second num:"
    read second_num
    let minus=$first_num-$second_num
    echo "$first_num-$second_num=$minus"
    return 0
}
function multiply_num()
{
    echo "please inut your first num:"
    read first_num
    echo "please inut your second num:"
    read second_num
    let multiply=$first_num*$second_num
    echo "$first_num*$second_num=$multiply"
    return 0
}

function divide_num()
{
    echo "please inut your first num:"
    read first_num
    echo "please inut your second num:"
    read second_num
    let divide=$first_num/$second_num
    echo "$first_num/$second_num=$divide"
    return 0
}
function main()
{
    clear
    tool_menu
    while :
    do
        menu_choice
        read menu_choice
        case $menu_choice in
            A|a) add_num ;;
            B|b) minus_num ;;
            C|c) multiply_num ;;
            D|d) divide_num ;;
            Q|q) break;;
            *) echo "Input error,please try agin.";;
        esac
    done
}
main
exit 0


 模板
#!/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."
}
function minus_num()
{

    echo "minus."
}
function multiply_num()
{
    echo "multiply."

}

function divide_num()
{

    echo "divide."

}
function main()
{
    clear 模板

    tool_menu
    while :
    do
        menu_choice
        read menu_choice
        case $menu_choice in
            A|a) add_num ;;
            B|b) minus_num ;;
            C|c) multiply_num ;;
            D|d) divide_num ;;
            Q|q) break;;
            *) echo "Input error,please try agin.";;
        esac
    done
}
main
exit 0

推荐阅读:
  1. shell运算(加、减、乘、除)
  2. Shell标准输入、输出和错误的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

shell he hell

上一篇:MAC SSH密钥登陆

下一篇:NetApp存储无法开机问题处理-(初始化重装系统)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》