interrupt a background process

Asked by Julianloui on 2013-01-07

What instructions can I include in a script to cause it to pause and respond to a keyboard interrupt such as ^C while it is executing background processes?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Last query:
2013-01-07
Last reply:
2013-02-25

you can use:

echo "Press ENTER to continue"
read somevar

Then you will need to press ENTER for the script to continue. Is this what you mean?

You can also add:

echo "Waiting 1 minute"
sleep 60

To add a pause in a script

Midnight Matt (randygaffer) said : #3

If the script is running in the foreground, it doesn't need any other interrupting for it
 to respond to keyboard commands involving the control key, such as ^Z (suspend) or ^C (stop). If you want, however, your script can be put into a `while` loop that will cause it to execute only when you press the ENTER key.

#!/bin/bash
while [[ -z $(read Varname) ]]; do
 various
 script
 commands
done

Can you help with this problem?

Provide an answer of your own, or ask Julianloui for more information if necessary.

To post a message you must log in.