Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have my program and I cannot figure out how to make the program loop back to the start. I have more of a program however this is the part where I would like the program to restart if I picked yes exit 0 and exit 1 are placeholders at the moment since I do not know how to make it loop. Thank you for your help in advance.

echo "Is that all sir? (Yes/No)"

if [ $word = "Yes" ] 
then exit 0

if [ $word = "No" ]
then exit 1

share|improve this question
Who will type yes or no? – Avinash Raj Apr 7 '14 at 14:53
@AvinashRaj This is a program to simulate a butler. it runs on terminal so the person running the program would type yes/no. – Sir_Dippingsauce Apr 7 '14 at 14:54
read is used to get input from the user. – Avinash Raj Apr 7 '14 at 14:56
This smells like a homework assignment. – psusi Apr 7 '14 at 19:44
Actually no, This is for my own free work. Sometimes i can get extra credit for turning in programs but this is for fun. Just so I could learn how to program. – Sir_Dippingsauce Apr 7 '14 at 20:56
up vote 4 down vote accepted
while [[ "$response" != "yes" ]]
    echo "Is that all? (Yes/No)"
    read -r response

References and advice:

share|improve this answer
However this still doesnt help figure out how to loop or restart the program. – Sir_Dippingsauce Apr 7 '14 at 16:28
@Sir_Dippingsauce: The while, do, done keywords make a loop. If the whole program is inside the while loop then the whole program restarts with each loop. – Zan Lynx Apr 7 '14 at 17:38
#!/usr/bin/env bash

# While running an infinite loop
while [ 1 ]; do
    # keep asking the user for input (Yes/No).
    echo "Is that all sir? (Yes/No): "
    # the read keyword assigns the input to the word variable
    read word
    # If the user types "Yes" 
    if [ $word = "Yes" ]; then
        # break the loop and finish the script.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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