I have the following Bash script. How can I make it pause on keypress or pause after a number of loops, but if I don’t press any key it should loop?
for i in `cat files`
do
echo $i
done
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think I initially misread your question. You can suspend the active process at any time by pressing
Ctrl+Z, and resume it with the fg builtin.In order to make the script pause after a number of iterations have been performed, you can use a counter variable and the modulo operator
%:My original answer was:
You can use the read builtin to have the shell wait until the user presses the
RETURNkey (or theEOFkey,Ctrl+D):You can use the
-toption ofreadin order have it time out and continue execution:The above will resume execution after 1 second if the user doesn’t press the
RETURNkey.