Idle bash script until CTRL+c event is logged Idle bash script until CTRL+c event is logged bash bash

Idle bash script until CTRL+c event is logged


Assuming you're connected to a TTY:

# idle waiting for abort from userread -r -d '' _ </dev/tty


The following will wait for Ctrl-C, then continue running:

( trap exit SIGINT ; read -r -d '' _ </dev/tty ) ## wait for Ctrl-Cecho script still running...


I had problem with read -r -d '' _ </dev/tty, I placed it in a script to prevent it from exiting and killing jobs. I have another script that uses dialog and calls the first one as a job, when the script reaches read -r -d '' _ </dev/tty the parent script dialog have a very weird behavior, like someone is constantly pressing the Esc key, this makes the dialog try to quit.

What I recommend is to use sleep you can sleep for a long time like 999 days sleep 999d and if you need for sure for it to never stop you wan put it in a while loop.