14

The trap builtin in bash has the following syntax

trap [-lp] [arg] [sigspec ...]

... Each sigspec is either a signal name or a signal number. Signal names are case insensitive and the SIG prefix is optional.

...

The bash manual points out that sigspec can be EXIT, DEBUG, RETURN, and ERR. Are they names of signals?

Why do I not find them in the list of all the signal names given below, even adding a prefix SIG to them?

Are they only related to bash shells but not to Linux OS? Are they bash shell signals but not Linux OS signals?

$ trap -l
 1) SIGHUP   2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT  7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
31) SIGSYS  34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX    

Thanks.

19

Those names have special meaning in bash for which usage is explained in the manual:

If a sigspec is 0 or EXIT, arg is executed when the shell exits. If a sigspec is DEBUG, the command arg is executed before every simple command, for command, case command, select command, every arithmetic for command, and before the first command executes in a shell function ...

If a sigspec is ERR, the command arg is executed whenever a pipeline (which may consist of a single simple command), a list, or a compound command returns a non-zero exit status, subject to the following conditions ...

14

These are not signals but it makes sense to use the trap mechanism for certain other situations, too. These names have meaning within bash only.

  • 1
    The EXIT trap is specified by POSIX though. – Kusalananda Aug 9 '17 at 18:40
  • @Kusalananda I did not mean that other shells did not support this. – Hauke Laging Aug 9 '17 at 18:45
  • 3
    @HaukeLaging Tecnically (and pedantically) speaking it makes the sentence "These names have meaning within bash only" incorrect. – Pharap Aug 9 '17 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.