Score:-1

How do I fix the syntax error 'do'?

nc flag

Here is a program I am working with but this is the output.

echo "Please select your favorite color"
echo "         or 4 to exit"
echo "---------------------------------"

#set menu prompt
menu="select color : "

#set menu list
select menu in Blue Yellow Red Quit
do
       case $menu in
               Blue)
                        echo "----------------------------"
                        echo "Your favorite color is Blue!"
                        echo "----------------------------"
                        ;;
               Yellow)
                        echo "----------------------------"
                        echo "Your favorite color is Yellow!"
                        echo "----------------------------"
                        ;;
               Red)
                        echo "----------------------------"
                        echo "Your favorite color is Red!"
                        echo "----------------------------"
                        ;;
               Quit)
                        echo "----------------------------"
                        echo "Thank you!"
                        echo "----------------------------"
                        ;;           
               *)
                        echo -e "Error: please try again (select 1......4)!"
       esac
Please select your favorite color
         or 4 to exit
./select.sh: line 36: syntax error: unexpected end of file

how do I fix it? Background: I'm brand new to linux and coding so I barely have any understanding to what's going on. I'm 100% youtube university


Edit: #?4 Error: please try again (select 1....4)! –

echo "Please select your favorite color"
echo "         or 4 to exit"
echo "---------------------------------"

#set menu prompt
menu="select color : "

#set menu list
select menu in Blue Yellow Red Quit
do
       case $menu in
               Blue)
                        echo "----------------------------"
                        echo "Your favorite color is Blue!"
                        echo "----------------------------"
                        ;;
               Yellow)
                        echo "----------------------------"
                        echo "Your favorite color is Yellow!"
                        echo "----------------------------"
                        ;;
               Red)
                        echo "----------------------------"
                        echo "Your favorite color is Red!"
                        echo "----------------------------"
                        ;;
               Quit)
                        echo "----------------------------"
                        echo "Thank you!"
                        echo "----------------------------"
                        ;;           
               *)
                        echo -e "Error: please try again (select 1......4)!"
       esac
done
cn flag
The error message `./select.sh: line 9: Select: command not found` is explicit. `Select` is not found. You want to use `select` instead.
Satoshi Nakamoto avatar
lc flag
ALWAYS always paste the code! Because this is a community based! Your code should be visible as both eyes to you and the community, your question/answers should be relevant to all! Not just you.
Mike Doza avatar
nc flag
Sorry about that now I'm getting
Mike Doza avatar
nc flag
./select.sh: line 37: syntax error: unexpected end of file, why does this happen?
Terrance avatar
id flag
From your image you posted, you didn't close out your `do` loop with `done` after it.
Mike Doza avatar
nc flag
Thanks guys. So how I do I end the 'do' loop with done?
Terrance avatar
id flag
After `esac` add `done` on the next line
Artur Meinild avatar
vn flag
Consider using `shellcheck` on your scripts. Also, I find [this reference](https://devhints.io/bash) handy.
Score:0
jp flag

General example:

sudodus@bionic64 ~ $ select i in whoami "echo 'Hello World'" break;do $i;done
1) whoami
2) echo 'Hello World'
3) break
#? 1
sudodus
#? 2
'Hello World'
#? 3
sudodus@bionic64 ~ $

Example matching your question:

It is enough with a 'oneliner'.

$ select i in Blue Yellow Red Quit;do if [ "$i" == "Quit" ];then break;else echo "Your favorite color is $i";fi;done
1) Blue
2) Yellow
3) Red
4) Quit
#? 1
Your favorite color is Blue
#? 2
Your favorite color is Yellow
#? 3
Your favorite color is Red
#? 4
$ select i in Blue Yellow Red Quit;do if [ "$i" == "Quit" ];then break;else echo "Your favorite color is $i";fi;done
1) Blue
2) Yellow
3) Red
4) Quit
#? 4
$ 
Score:0
vn flag

Your script should be :

do
   case $menu in
       1) echo "----------------------------"
          echo "Your favorite color is Blue!"
          echo "----------------------------"
          ;;
       2) echo "----------------------------"
          echo "Your favorite color is Yellow!"
          echo "----------------------------"
          ;;
       3) echo "----------------------------"
          echo "Your favorite color is Red!"
          echo "----------------------------"
          ;;
       4) echo "----------------------------"
          echo "Thank you!"
          echo "----------------------------"
          exit
          ;;           
       *) echo -e "Error: please try again (select 1......4)!"
   esac
done
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.