0

这是脚本,我不断收到意外的 fi 错误。我错过了什么?..(我开始将 [] 用于 if 语句,但由于我使用此命令,我删除了 [] .. 这样可以吗?)

if type "java" 2>&1;
    then
        echo "All ok . . . ";
        exit                                                                                                                                              
    else
        read -n1 -r -p "Yo need to install"
        while true; do
            echo "Want to install??"
            select yn in "y" "n"; do
                case $yn in
                    y ) echo "Installing here..."; break;;
                    n ) echo "Ok... stopping..."; exit;;
                esac
            done
        exit
fi

谢谢!

4

2 回答 2

3

while以 结尾done,而不是exit。试试这个:

if type "java" 2>&1;
    then
        echo "All ok . . . ";
        exit                                                                                                                                              
    else
        read -n1 -r -p "Yo need to install"
        while true; do
            echo "Want to install??"
            select yn in "y" "n"; do
                case $yn in
                    y ) echo "Installing here..."; break;;
                    n ) echo "Ok... stopping..."; exit;;
                esac # <-- ending `case`
            done     # <-- ending `select`
        done         # <-- while ends with `done`, not `exit`!
fi                   # <-- ending `if`
于 2013-07-06T00:13:53.660 回答
1

你有一个exit在最后一个fi; 我想这应该是一个done.

于 2013-07-06T00:14:08.930 回答