Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

fi
share|improve this question
    
Who will type yes or no? –  Avinash Raj Apr 7 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 at 14:54
    
read is used to get input from the user. –  Avinash Raj Apr 7 at 14:56
    
This smells like a homework assignment. –  psusi Apr 7 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 at 20:56
add comment

2 Answers 2

up vote 4 down vote accepted
response=no
while [[ "$response" != "yes" ]]
do
    echo "Is that all? (Yes/No)"
    read -r response
done

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 at 16:28
2  
@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 at 17:38
add comment
#!/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.
        break
    fi
done
share|improve this answer
add comment

Your Answer

 
discard

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.