Let's say I have a script which acts as an alarm. Say you set it for five minutes and it does the following:
printf '%s\n' 'Alarm set for 5 minutes'
sleep 300 && printf '%s\n' 'Alarm!'
How can I implement a way to continuously monitor for a pause key, say "p" or "SPC", then wait until a key is pressed again to resume normal execution of the script? I want a way for the user to pause the alarm.
Edit: To clarify, I want to continuously monitor for a pause key while running other code. This is as opposed to stopping execution to listen on stin.