I want to pause input in a shell script, and prompt the user for choices. The standard 'Yes, No, or Cancel' type question. How do I accomplish this in a typical bash prompt?

share|improve this question

26 Answers 26

At least five answers for one generic question.

Depending on

  • compliant: could work on poor systems with generic environments
  • specific: using so called bashisms

and if you want

  • simple ``in line'' question / answer (generic solutions)
  • pretty formatted interfaces, like or more graphical using libgtk or libqt...
  • use powerful readline history capability

1. POSIX generic solutions

You could use the read command, followed by if ... then ... else:

echo -n "Is this a good question (y/n)? "
read answer
if echo "$answer" | grep -iq "^y" ;then
    echo Yes
else
    echo No
fi

POSIX, but single key feature

But if you don't want the user to have to hit Return, you could write:

(Edited: As @JonathanLeffler rightly suggest, saving stty's configuration could be better than simply force them to sane.)

echo -n "Is this a good question (y/n)? "
old_stty_cfg=$(stty -g)
stty raw -echo ; answer=$(head -c 1) ; stty $old_stty_cfg # Careful playing with stty
if echo "$answer" | grep -iq "^y" ;then
    echo Yes
else
    echo No
fi

Note: This was tested under , , , and !

Same, but waiting explicitly for y or n:

#/bin/sh
echo -n "Is this a good question (y/n)? "
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y" ;then
    echo Yes
else
    echo No
fi

Using dedicated tools

There are many tools which were built using libncurses, libgtk, libqt or other graphical libraries. For example, using whiptail:

if whiptail --yesno "Is this a good question" 20 60 ;then
    echo Yes
else
    echo No
fi

Depending on your system, you may need to replace whiptail with another similiar tool:

dialog --yesno "Is this a good question" 20 60 && echo Yes

gdialog --yesno "Is this a good question" 20 60 && echo Yes

kdialog --yesno "Is this a good question" 20 60 && echo Yes

where 20 is height of dialog box in number of lines and 60 is width of the dialog box. These tools all have near same syntax.

DIALOG=whiptail
if [ -x /usr/bin/gdialog ] ;then DIALOG=gdialog ; fi
if [ -x /usr/bin/xdialog ] ;then DIALOG=xdialog ; fi
...
$DIALOG --yesno ...

2. Bash specific solutions

Basic in line method

read -p "Is this a good question (y/n)? " answer
case ${answer:0:1} in
    y|Y )
        echo Yes
    ;;
    * )
        echo No
    ;;
esac

I prefer to use case so I could even test for yes | ja | si | oui if needed...

in line with single key feature

Under bash, we can specify the length of intended input for for the read command:

read -n 1 -p "Is this a good question (y/n)? " answer

Under bash, read command accepts a timeout parameter, which could be useful.

read -t 3 -n 1 -p "Is this a good question (y/n)? " answer
[ -z "$answer" ] && answer="Yes"  # if 'yes' have to be default choice

Some tricks for dedicated tools

More sophisticated dialog boxes, beyond simple yes - no purposes:

dialog --menu "Is this a good question" 20 60 12 y Yes n No m Maybe

Progress bar:

dialog --gauge "Filling the tank" 20 60 0 < <(
    for i in {1..100};do
        printf "XXX\n%d\n%(%a %b %T)T progress: %d\nXXX\n" $i -1 $i
        sleep .033
    done
) 

Little demo:

#!/bin/sh
while true ;do
    [ -x "$(which ${DIALOG%% *})" ] || DIALOG=dialog
    DIALOG=$($DIALOG --menu "Which tool for next run?" 20 60 12 2>&1 \
            whiptail       "dialog boxes from shell scripts" >/dev/tty \
            dialog         "dialog boxes from shell with ncurses" \
            gdialog        "dialog boxes from shell with Gtk" \
            kdialog        "dialog boxes from shell with Kde" ) || exit
    clear;echo "Choosed: $DIALOG."
    for i in `seq 1 100`;do
        date +"`printf "XXX\n%d\n%%a %%b %%T progress: %d\nXXX\n" $i $i`"
        sleep .0125
      done | $DIALOG --gauge "Filling the tank" 20 60 0
    $DIALOG --infobox "This is a simple info box\n\nNo action required" 20 60
    sleep 3
    if $DIALOG --yesno  "Do you like this demo?" 20 60 ;then
        AnsYesNo=Yes; else AnsYesNo=No; fi
    AnsInput=$($DIALOG --inputbox "A text:" 20 60 "Text here..." 2>&1 >/dev/tty)
    AnsPass=$($DIALOG --passwordbox "A secret:" 20 60 "First..." 2>&1 >/dev/tty)
    $DIALOG --textbox /etc/motd 20 60
    AnsCkLst=$($DIALOG --checklist "Check some..." 20 60 12 \
        Correct "This demo is useful"        off \
        Fun        "This demo is nice"        off \
        Strong        "This demo is complex"        on 2>&1 >/dev/tty)
    AnsRadio=$($DIALOG --radiolist "I will:" 20 60 12 \
        " -1" "Downgrade this answer"        off \
        "  0" "Not do anything"                on \
        " +1" "Upgrade this anser"        off 2>&1 >/dev/tty)
    out="Your answers:\nLike: $AnsYesNo\nInput: $AnsInput\nSecret: $AnsPass"
    $DIALOG --msgbox "$out\nAttribs: $AnsCkLst\nNote: $AnsRadio" 20 60
  done

5. Using readline's history

Example:

#!/bin/bash

set -i
HISTFILE=~/.myscript.history
history -c
history -r

myread() {
    read -e -p '> ' $1
    history -s ${!1}
}
trap 'history -a;exit' 0 1 2 3 6

while myread line;do
    case ${line%% *} in
        exit )  break ;;
        *    )  echo "Doing something with '$line'" ;;
      esac
  done

This will create a file .myscript.history in your $HOME directory, than you could use readline's history commands, like Up, Down, Ctrl+r and others.

share|improve this answer
2  
Note that stty provides the -g option for use: old_stty=$(stty -g); stty raw -echo; …; stty "$old_stty". This restores the setting exactly as they were found, which may or may not be the same as stty -sane. – Jonathan Leffler Feb 7 '15 at 5:09
    
Yes, there is not 4., but I thinks there is more than one thing in 3.! ;-) – F. Hauri Oct 29 '15 at 8:03
    
Readline's history script re-written! – F. Hauri Jan 18 '16 at 15:26
1  
read answer will interpret backslashes before spaces and line feeds, and otherwise strip them which is rarely intended. Use read -r answer instead as per SC2162. – vlfig Mar 31 '17 at 14:03
    
@vlfig A agree: expecting backslashes from user input in a Yes/No/Cancel dialog is rarely intended... I think It's the main reason because I've not used -r option. – F. Hauri Mar 31 '17 at 16:17

With php, this is powerful for shell scripts:

#!/usr/bin/php

<?php 

$yo = readline("Do you wish to install this program? [Y/y] or [ctrl+c to quit]");

if ($yo == "Y" || $yo == "y") {   
    echo "Installing..";
    system("sudo apt install ...");
 }

The php-cli package only is mandatory for this.

share|improve this answer
    
I assume this works, but I can't upvote any answer that uses PHP due to its position as one of the worst organized languages out there. I'm not sure why I'd use PHP in a script vs a more appropriate shell language like Bash, Perl, or even Ruby. – Myrddin Emrys Aug 9 '17 at 2:12
    
You can't prove that it's badly organized or inappropriate, but I show here it isn't, and even better. Russell's teapot achievement, to exit his orbit to the eternity. – Cryptopat Sep 9 '17 at 22:49
    
Upvoting your answer just because I never knew I could write scripts in php for a linux machine. – Raja Anbazhagan Dec 18 '17 at 12:08
    
Thank you. Here is some of my works around shell scripts and php. github.com/webdev23/phi – Cryptopat Dec 18 '17 at 21:15

Confirm with clean user input

Function:

@confirm() {
  local message="$1"

  echo -n "> $message (y/n) "

  while true ; do
    read -s -n 1 choice
    case "$choice" in
      y|Y ) echo "Y" ; return 0 ;;
      n|N ) echo "N" ; return 1 ;;
    esac
  done
}

Usage:

if @confirm 'Confirm?' ; then
  echo "Yes"
else
  echo "No"
fi
share|improve this answer
up vote 1170 down vote accepted

The simplest and most widely available method to get user input at a shell prompt is the read command. The best way to illustrate its use is a simple demonstration:

while true; do
    read -p "Do you wish to install this program?" yn
    case $yn in
        [Yy]* ) make install; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

Another method, pointed out by Steven Huwig, is Bash's select command. Here is the same example using select:

echo "Do you wish to install this program?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) make install; break;;
        No ) exit;;
    esac
done

With select you don't need to sanitize the input – it displays the available choices, and you type a number corresponding to your choice. It also loops automatically, so there's no need for a while true loop to retry if they give invalid input.

Also, please check out the excellent answer by F. Hauri.

share|improve this answer
12  
read -p "Do you wish to install this program? " yn ... – Steve Baker Oct 22 '08 at 17:21
18  
Using Bash in OS X Leopard, I changed exit to break to keep from closing the tab when I selected 'no'. – Trey Piepmeier Dec 2 '09 at 18:34
3  
@Trey, you might want to use return instead of exit in that case. – glenn jackman May 13 '11 at 13:06
4  
I just want to thank whoever tried to fix my syntax error, even though your edit was rejected. I'm sorry they rejected it; you were correct. Thank you for the fix. – Myrddin Emrys Jul 10 '14 at 5:24
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. – Travesty3 Jan 4 at 15:08

Use the read command:

echo Would you like to install? "(Y or N)"

read x

# now check if $x is "y"
if [ "$x" = "y" ]; then
    # do something here!
fi

and then all of the other stuff you need

share|improve this answer

The easiest way to achieve this with the least number of lines is as follows:

read -p "<Your Friendly Message here> : y/n/cancel" CONDITION;

if [ "$CONDITION" == "y" ]; then
   # do something here!
fi

The if is just an example: it is up to you how to handle this variable.

share|improve this answer

I noticed that no one posted an answer showing multi-line echo menu for such simple user input so here is my go at it:

#!/bin/bash

function ask_user() {    

echo -e "
#~~~~~~~~~~~~#
| 1.) Yes    |
| 2.) No     |
| 3.) Quit   |
#~~~~~~~~~~~~#\n"

read -e -p "Select 1: " choice

if [ "$choice" == "1" ]; then

    do_something

elif [ "$choice" == "2" ]; then

    do_something_else

elif [ "$choice" == "3" ]; then

    clear && exit 0

else

    echo "Please select 1, 2, or 3." && sleep 3
    clear && ask_user

fi
}

ask_user

This method was posted in the hopes that someone may find it useful and time-saving.

share|improve this answer
inquire ()  {
  echo  -n "$1 [y/n]? "
  read answer
  finish="-1"
  while [ "$finish" = '-1' ]
  do
    finish="1"
    if [ "$answer" = '' ];
    then
      answer=""
    else
      case $answer in
        y | Y | yes | YES ) answer="y";;
        n | N | no | NO ) answer="n";;
        *) finish="-1";
           echo -n 'Invalid response -- please reenter:';
           read answer;;
       esac
    fi
  done
}

... other stuff

inquire "Install now?"

...
share|improve this answer
1  
Put four spaces in the beginning of each line to preserve the formatting of code. – Jouni K. Seppänen Oct 22 '08 at 17:15
8  
Why we providing 'y' and 'n' as parameters to inquire() if the case switches are hardcoded? That's just asking for misuse. They are fixed parameters, not changable, so the echo on line 2 should read: echo -n "$1 [Y/N]? " They can't be changed, so they shouldn't be supplied. – Myrddin Emrys Oct 22 '08 at 20:06
1  
@MyrddinEmrys Could you please elaborate your comment? Or post a link to an article or a couple of keywords so I could do research on my own. – Mateusz Piotrowski Mar 26 '16 at 20:46
3  
@MateuszPiotrowski The answer has been edited and improved since I made my comment. You can click the 'edited Dec 23' link above to view all the past versions of this answer. Back in 2008, the code was quite different. – Myrddin Emrys Mar 27 '16 at 5:21

I've used the case statement a couple of times in such a scenario, using the case statment is a good way to go about it. A while loop, that ecapsulates the case block, that utilizes a boolean condition can be implemented in order to hold even more control of the program, and fulfill many other requirements. After the all the conditions have been met, a break can be used which will pass control back to the main part of the program. Also, to meet other conditions, of course conditional statements can be added to accompany the control structures: case statement and possible while loop.

Example of using a case statement to fulfill your request

#! /bin/sh 

# For potential users of BSD, or other systems who do not
# have a bash binary located in /bin the script will be directed to
# a bourne-shell, e.g. /bin/sh

# NOTE: It would seem best for handling user entry errors or
# exceptions, to put the decision required by the input 
# of the prompt in a case statement (case control structure), 

echo Would you like us to perform the option: "(Y|N)"

read inPut

case $inPut in
    # echoing a command encapsulated by 
    # backticks (``) executes the command
    "Y") echo `Do something crazy`
    ;;
    # depending on the scenario, execute the other option
    # or leave as default
    "N") echo `execute another option`
    ;;
esac

exit
share|improve this answer

You want:

  • Bash builtin commands (i.e. portable)
  • Check TTY
  • Default answer
  • Timeout
  • Colored question

Snippet

do_xxxx=y                      # In batch mode => Default is Yes
[[ -t 0 ]] &&                  # If tty => prompt the question
read -t 5 -n 1 -p $'\e[1;32m
Do xxxx? (Y/n)\e[0m ' do_xxxx  # Store the answer in $do_xxxx
if [[ $do_xxxx =~ ^(y|Y|)$ ]]  # Do if 'y', 'Y' or empty
then
    xxxx
fi

Explanations

  • [[ -t 0 ]] && read ... => Call read only in TTY
  • read -t 5 => Timeout 5 seconds
  • read -n 1 => Wait for one character
  • $'\e[1;32m ... \e[0m ' => Print in green
    (readable on both white/black backgrounds)
    • [[ $do_xxxx =~ ^(y|Y|)$ ]] => bash regex

Timeout => Default answer is No

do_xxxx=y
[[ -t 0 ]] && {
read -t 5 -n 1 -p $'\e[1;32m
Do xxxx? (Y/n)\e[0m ' do_xxxx ||  # read 'fails' on timeout
do_xxxx=n ; }                     # Timeout => answer No
if [[ $do_xxxx =~ ^(y|Y|)$ ]]
then
    xxxx
fi
share|improve this answer
2  
I like the inclusion of a timeout, nice feature. – Myrddin Emrys Mar 4 '16 at 19:36
2  
thanks a lot. it's so useful – Ghasem Pahlavan Jan 22 '17 at 9:59

more generic would be:

function menu(){
    title="Question time"
    prompt="Select:"
    options=("Yes" "No" "Maybe")
    echo "$title"
    PS3="$prompt"
    select opt in "${options[@]}" "Quit/Cancel"; do
        case "$REPLY" in
            1 ) echo "You picked $opt which is option $REPLY";;
            2 ) echo "You picked $opt which is option $REPLY";;
            3 ) echo "You picked $opt which is option $REPLY";;
            $(( ${#options[@]}+1 )) ) clear; echo "Goodbye!"; exit;;
            *) echo "Invalid option. Try another one.";continue;;
         esac
     done
     return
}
share|improve this answer

You can use the built-in read command. Use the -p option to prompt the user with a question.

Since BASH4, you can now use -i to suggest an answer, so the user only have to press return to enter it :

read -e -p "Enter the path to the file: " -i "/usr/local/etc/" FILEPATH
echo $FILEPATH

(But remember to use the "readline" option -e to allow line editing with arrow keys)

share|improve this answer
2  
It should be noted that FILEPATH is the variable name you have chosen, and is set with the answer to the command prompt. So if you were to then run vlc "$FILEPATH", for example, vlc would open that file. – Ken Sharp Feb 23 '15 at 1:45

As a friend of a one line command I used the following:

while [ -z $prompt ]; do read -p "Continue (y/n)?" choice;case "$choice" in y|Y ) prompt=true; break;; n|N ) exit 0;; esac; done; prompt=;

Written longform, it works like this:

while [ -z $prompt ];
  do read -p "Continue (y/n)?" choice;
  case "$choice" in
    y|Y ) prompt=true; break;;
    n|N ) exit 0;;
  esac;
done;
prompt=;
share|improve this answer
    
Can you clarify the use of the prompt variable? Looks to me like it's wiped after the one liner, so how do you use the line to DO anything? – Myrddin Emrys Jun 5 '15 at 6:37
    
prompt is wiped after the while loop. Because I want the prompt variable to be initialized afterwards (since I am using the statement more often). Having this line in a shell-script will only proceed if y|Y is typed and exit if n|N is typed or repeat asking for input for everything else. – ccDict Jun 5 '15 at 6:42
    
Better clear it before the loop – BeniBela Jan 27 '17 at 23:36
read -e -p "Enter your choice: " choice

The -e option enables the user to edit the input using arrow keys.

If you want to use a suggestion as input:

read -e -i "yes" -p "Enter your choice: " choice

-i option prints a suggestive input.

share|improve this answer
1  
(note: options are specific to bash (don't work in zsh) – AdrieanKhisbe May 10 '15 at 17:41
    
yap, -e -i don't work in sh (Bourne shell), but the question is tagged bash specifically.. – Jahid May 10 '15 at 20:22
    
I know, :) I was just adding this information. – AdrieanKhisbe May 11 '15 at 11:27

One simple way to do this is with xargs -p or gnu parallel --interactive.

I like the behavior of xargs a little better for this because it executes each command immediately after the prompt like other interactive unix commands, rather than collecting the yesses to run at the end. (You can Ctrl-C after you get through the ones you wanted.)

e.g.,

echo *.xml | xargs -p -n 1 -J {} mv {} backup/
share|improve this answer
    
Not bad, but xargs --interactive is limited to yes or no. As long as that's all you need that can be enough, but my original question gave an example with three possible results. I really like that it is streamable though; many common scenarios would benefit from its ability to be piped. – Myrddin Emrys Apr 9 '15 at 0:25
    
I see. My thinking was that "cancel" meant to simply stop all further execution, which this supports via Ctrl-C, but if you need to do something more complex on cancel (or on no) this won't suffice. – Joshua Goldberg Jun 7 '15 at 22:21

Inspired by the answers of @Mark and @Myrddin I created this function for a universal prompt

uniprompt(){
    while true; do
        echo -e "$1\c"
        read opt
        array=($2)
        case "${array[@]}" in  *"$opt"*) eval "$3=$opt";return 0;; esac
        echo -e "$opt is not a correct value\n"
    done
}

use it like this:

unipromtp "Select an option: (a)-Do one (x)->Do two (f)->Do three : " "a x f" selection
echo "$selection"
share|improve this answer
    
I'm not a fan of the use of eval; just asking to be abused with evil input. – Myrddin Emrys Apr 9 '15 at 0:29
echo "Please enter some input: "
read input_variable
echo "You entered: $input_variable"
share|improve this answer
10  
I disagree, because it only implements a portion of the functionality of the 'Yes, No, Cancel' dialog in DOS. The part it fails to implement is input checking... looping until a valid answer is received. – Myrddin Emrys Sep 23 '16 at 15:49
    
(The original question title was "How do I prompt for input in a Linux shell script?") – Pistos Jul 9 '17 at 16:53
2  
But the original question description is unchanged, and always asked for a response to a Yes/No/Cancel prompt. The title has been updated to be clearer than my original one, but the question description was always clear (in my opinion). – Myrddin Emrys Sep 6 '17 at 13:52

I suggest you use dialog...

Linux Apprentice: Improve Bash Shell Scripts Using Dialog

The dialog command enables the use of window boxes in shell scripts to make their use more interactive.

it's simple and easy to use, there's also a gnome version called gdialog that takes the exact same parameters, but shows it GUI style on X.

share|improve this answer
    
For the casual reader, have look to a snippet using the dialog command here: stackoverflow.com/a/22893526/363573 – Stephan Dec 2 '14 at 19:41

Sorry for posting on such an old post. Some weeks ago I was facing a similar problem, in my case I needed a solution which also worked within an online installer-script, eg: curl -Ss https://raw.github.com/_____/installer.sh | bash

Using read yesno < /dev/tty works fine for me:

echo -n "These files will be uploaded. Is this ok? (y/n) "
read yesno < /dev/tty

if [ "x$yesno" = "xy" ];then

   # Yes
else

   # No
fi

Hope this helps someone.

share|improve this answer
    
An important part of this is input validation. I think adapting my first example to accept tty input as you did would have done as well for you, and also gotten looping on bad input (imagine a few characters in the buffer; your method would force the user to always choose no). – Myrddin Emrys May 22 '14 at 13:03

To get a nice ncurses-like inputbox use the command dialog like this:

#!/bin/bash
if (dialog --title "Message" --yesno "Want to do something risky?" 6 25)
# message box will have the size 25x6 characters
then 
    echo "Let's do something risky"
    # do something risky
else 
    echo "Let's stay boring"
fi

The dialog package is installed by default at least with SUSE Linux.

share|improve this answer

Multiple choice version:

ask () {                        # $1=question $2=options
    # set REPLY
    # options: x=..|y=..
    while $(true); do
        printf '%s [%s] ' "$1" "$2"
        stty cbreak
        REPLY=$(dd if=/dev/tty bs=1 count=1 2> /dev/null)
        stty -cbreak
        test "$REPLY" != "$(printf '\n')" && printf '\n'
        (
            IFS='|'
            for o in $2; do
                if [ "$REPLY" = "${o%%=*}" ]; then
                    printf '\n'
                    break
                fi
            done
        ) | grep ^ > /dev/null && return
    done
}

Example:

$ ask 'continue?' 'y=yes|n=no|m=maybe'
continue? [y=yes|n=no|m=maybe] g
continue? [y=yes|n=no|m=maybe] k
continue? [y=yes|n=no|m=maybe] y
$

It will set REPLY to y (inside the script).

share|improve this answer

This solution reads a single character and calls a function on a yes response.

read -p "Are you sure? (y/n) " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    do_something      
fi
share|improve this answer
    
why the 'echo' ? – Jav Apr 1 '14 at 13:27
1  
@Jav the echo prints a newline after your response. Without it, the next thing to be printed would appear immediately after your response on the same line. Try removing the echo to see for yourself. – Dennis Apr 1 '14 at 16:10
yn() {
  if [[ 'y' == `read -s -n 1 -p "[y/n]: " Y; echo $Y` ]];
  then eval $1;
  else eval $2;
  fi }
yn 'echo yes' 'echo no'
yn 'echo absent no function works too!'
share|improve this answer
    
This seems complex and fragile. How about just yn(){ read -s -n 1 -p '[y/n]'; test "$REPLY" = "y" ; } yn && echo success || echo failure – tripleee May 21 '14 at 11:44
    
The above code should work without the evals. – agc May 15 '17 at 2:31

Here's something I put together:

#!/bin/sh

promptyn () {
    while true; do
        read -p "$1 " yn
        case $yn in
            [Yy]* ) return 0;;
            [Nn]* ) return 1;;
            * ) echo "Please answer yes or no.";;
        esac
    done
}

if promptyn "is the sky blue?"; then
    echo "yes"
else
    echo "no"
fi

I'm a beginner, so take this with a grain of salt, but it seems to work.

share|improve this answer
6  
If you change case $yn in to case ${yn:-$2} in then you can use the second argument as the default value, Y or N. – jchook Jul 24 '13 at 20:21
read -p "Are you alright? (y/n) " RESP
if [ "$RESP" = "y" ]; then
  echo "Glad to hear it"
else
  echo "You need more bash programming"
fi
share|improve this answer

Bash has select for this purpose.

select result in Yes No Cancel
do
    echo $result
done
share|improve this answer
14  
+1 Geniously simple solution. Only thing: This will prompt and promt and prompt... until you add an exit inside :) – kaiser Feb 28 '13 at 0:24
4  
(kaiser: To break from it, just enter the EOT: Ctrl-D. But of course, real code using it will need a break or an exit in the body.) – Zorawar Apr 22 '14 at 22:50
5  
This will not allow you to enter y or n, though.You choose by entering 1 2 or 3. – djjeck Sep 10 '14 at 16:03
    
exit will exit the script all together, break will only exit the loop you are in (if you are on a while or case loop) – wranvaud Nov 6 '16 at 17:48

protected by Yu Hao Sep 24 '13 at 3:30

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.