AAlvz
AAlvz

Reputation: 1109

unexpected fi in bash script

This is the script and I keep getting an unexpected fi error. What am I missing? .. (I started using [] for the if statement but since I'm using this command I deleted the [] .. Is it ok this way?)

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

thanks!

Upvotes: 0

Views: 458

Answers (2)

DaoWen
DaoWen

Reputation: 33029

while ends with done, not exit. Try this:

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`

Upvotes: 3

Costi Ciudatu
Costi Ciudatu

Reputation: 38255

You have an exit before the last fi; I suppose that should be a done.

Upvotes: 1

Related Questions