Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why does it keep repeating after finishing the gatorade option?

+4 votes
asked Sep 23, 2022 by Nathon Brentnall (160 points)
PS3='What do you prefer to drink? '
options=("Water" "Gatorade" "Milk" "Juice" "Tea" "Too gangster for liquids!")
select opt in "${options[@]}"
do
    case $opt in
        "Water")
            echo "you chose option $REPLY which is $opt"
            break
            ;;
        "Gatorade")
            echo "you chose option $REPLY which is $opt"
            PS4='What color of gatorade do you prefer? '
            options=("Red" "Blue" "Yellow" "Green" "Orange" "Any")
            select opt in "${options[@]}"
            do
                case $opt in
                    "Red")
                        echo "you chose option $REPLY which is $opt"
                        break
                        ;;
                    "Blue")
                        echo "you chose option $REPLY which is $opt"
                        break
                        ;;
                    "Yellow")
                        echo "you chose option $REPLY which is $opt"
                        break
                        ;;
                    "Green")
                        echo "you chose option $REPLY which is $opt"
                        break
                        ;;
                    "Orange")
                        echo "you chose option $REPLY which is $opt"
                        break
                        ;;
                    "Any")
                        echo "you chose option $REPLY which is $opt"
                        break
                        ;;
                    *) echo "invalid option $REPLY";;
                esac
            done
            ;;
        "Milk")
            echo "you chose option $REPLY which is $opt"
            break
            ;;
        "Juice")
            echo "you chose option $REPLY which is $opt"
            break
            ;;
        "Tea")
            echo "you chose option $REPLY which is $opt"
            break
            ;;
        "Too gangster for liquids!")
            echo "you chose option $REPLY which is $opt"
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

1 Answer

+1 vote
answered Sep 25, 2022 by xDELLx (10,500 points)
 34                     "Orange")
 35                         echo "you chose option $REPLY which is $op"
 36                         break
 37                         ;;
 38                     "Any")
 39                         echo "you chose option $REPLY which is $op"
 40                         break
 41                         ;;
 42                     *) echo "invalid option $REPLY";;
 43                 esac
 44             done
 45             break
 46             ;;
 47         "Milk")
 48             echo "you chose option $REPLY which is $opt"
 49             break
 50             ;;
 51         "Juice")



Line #45 needs to have break, to break outer loop.

Add line 45 & ur good!!

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...