Ctrl + C sends a SIGINT signal to all processes in the foreground a group of processes . While tail is running, the process group consists of a tail process and a shell using a script.
Use trap to override the default behavior of the signal.
trap " " INT tail -f nohup.out trap - INT echo 5
The trap code does nothing, so the shell moves on to the next command ( echo 5 ) if it receives SIGINT. Note that there is a space between quotation marks in the first line; any shell code that does nothing will do, with the exception of an empty line, which would mean ignoring the signal altogether (this cannot be used because it will cause tail also ignore the signal). The second call to trap restores the default behavior, so after the third line a Ctrl + C will abort the script again.
source share