bash脚本中意外的fi

时间:2013-07-06 00:10:29

标签: bash if-statement

这是脚本,我不断收到意外的错误。我错过了什么? ..(我开始使用[]作为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

谢谢!

2 个答案:

答案 0 :(得分:3)

whiledone而不是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`

答案 1 :(得分:1)

你在exit之前有一个fi;我想这应该是done