How can I ask a user for input and continue working with my script if no response is received within a specified period of time.
For example, this is what I have at the moment:
read -p "Would you like to reboot? (y/n) " yn
case $yn in
[Yy]* ) echo "shutting down"; break;;
[Nn]* ) echo "cancelled shutdown"; break;;
* ) echo "Please answer y or n.";;
esac
However, I want the invitation to sit on the terminal for 2 minutes, and then if the response is not received, continue with my script.
I have vague thoughts about how this is possible by starting the subshell entry, but I don’t know how to start the timeout at the same time. The timeout pseudocode might look something like this:
sleep 200s
kill the prompt
continue...
source
share