Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 43
    Using Bash in OS X Leopard, I changed exit to break to keep from closing the tab when I selected 'no'. Commented Dec 2, 2009 at 18:34
  • 1
    How does this work with options longer than Yes or No? In the case clause, do you write something like: Install program and do nothing afterwards ) make install; break; Commented Feb 29, 2012 at 6:12
  • 1
    @Shawn Using read you can, of course, use any glob or regex pattern supported by the bash shell's switch statement. It just matches the text typed to your patterns until it finds a match. Using select, the list of choices is given to the command and it displays them to the user. You can have the items in the list be as long or as short as you like. I recommand checking their man pages for comprehensive usage information. Commented Feb 29, 2012 at 21:45
  • 4
    why is there a break in the select if there is no loop? Commented Jun 16, 2014 at 10:46
  • 1
    FWIW, I used this example to create a script that I intended to trigger via a remote SSH session. My SSH command looked like this: ssh my-server 'path/to/myscript.sh'. When executing this way, the prompt text for the read -p command does not show up. However, output from the echo command does. So for me, the better solution was to use echo -n "Do something? " followed by read yn. Commented Jan 4, 2018 at 15:08