更新子菜单变量

时间:2016-12-18 20:25:11

标签: bash unix

我对此bash脚本有疑问:

#!/bin/bash
G=100

echo $G

main_menu()
{

    while :
    do
        clear

        echo "Select from menu"
        echo "[1] Press 1 to show savings"
        echo "[2] Press 2 to withdraw savings"
        echo "[3] Press 3 to exit"

        echo "Enter your menu choice [1-3]: \c "
        read -r  m_menu

        case "$m_menu" in
            1) option_1;;

            2) option_2;;

            3) exit 0;;

            *) echo "\nERROR: Please select a valid menu choice";
                echo "Press ENTER To Continue..." ; read ;;
        esac
    done
}

option_1()
{
    clear

    echo "Your balance is $G"

    echo "\nPress ENTER to return to menu..."  
    read

    return
}

option_2()
{
    clear

    echo "Withdraw savings"
    read -rp "Enter amount to withdraw: " num

    if [ $num -le $G ]; then
        answer=$(echo $(( G - num )))

        echo "Your new balance is: $answer"
        echo "$answer" | tee "$G"
    elif [ $num -gt $G ]; then
        echo "No: not eough money in your balance"
    fi

    read

    return
}

main_menu  

问题如下:如何确保一旦取出储蓄,我的储蓄计数将会更新?因为如果我提取90美元,显然当我回到余额时它应该是10美元,但这对我来说不起作用(它仍然说储蓄余额是100美元)

我该怎么办?

谢谢(抱歉我的英语不好)

1 个答案:

答案 0 :(得分:1)

您必须在代码中更新G.

url(r'^(?P<date>\d{4}-\d{2}-\d{2})/$', views.index, name='index'),