Reputation: 147
I just need an example of script that repeat all the same actions in a loop til we ask to stop it. Say I want the user to type y or n for exit, how would i implement it. I have something like echo "Input y or n to exit" read input if [ "$input = y ] then ....... else ........ fi
For the same script demonstrated in the answer below or maybe other example, how can I have this addition to make the user control the script without having to exit only by pressing control+z
Upvotes: 0
Views: 235
Reputation: 247042
while true; do
commands ...
read -p "Continue (y/n) ? " answer
case "$answer" in
Y*|y*) : ;;
*) break
esac
done
If the user responds with "Y" or "y", do nothing, in which case the loop continues. Otherwise break the loop.
Upvotes: 1
Reputation: 212484
while true; do echo hello; sleep 1; done
will run until you send a signal.
Upvotes: 3