In a bash script, is there a simple way to wait for a signal, something like:
wait -s SIGINT
or whatever? Maybe just
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
wait is exclusively used in a parent process to wait for the termination of a child process (and to access its exit status).
Furthermore, no process may trap the
KILL signal (the original question used
KILL as example).
Also, to "wait for a signal" is an unusual thing to want to do, as signals are asynchronous events.
You could, obviously, do something like
trap 'quit=1' USR1 quit=0 while [ "$quit" -ne 1 ]; do printf 'do "kill -USR1 %d" to exit this loop after the sleep\n' "$$" sleep 1 done
bash the same thing could be done with a
read with a timeout:
while ! read -t 1; do echo 'press enter to exit loop' done
read -p 'press enter to continue'