bash 4.3 on Kubuntu Trusty 64 bit. Please see the following two files:
#! /bin/bash trap "echo Exiting" INT cat </dev/urandom >/dev/null echo Hello
#! /bin/bash trap "echo Exiting" EXIT cat </dev/urandom >/dev/null echo Hello
Now upon hitting ^C, trapping SIGINT prints both
Hello whereas trapping EXIT prints
Exiting only but with an extra newline:
$ ./trapping-int ^CExiting Hello $ ./trapping-exit ^CExiting $
I would like to know the reason for the differing behaviour. Also, can I safely assume that EXIT is always called even if INT is given by ^C?
Commenting out the last line in both scripts causes trapping SIGINT to no longer print the Hello but trapping EXIT still prints the extra newline. I'd like to know the reason here too.