Is it necessary to specify traps other than EXIT?

前端 未结 3 1427
栀梦
栀梦 2021-02-02 07:28

I see a lot of shell scripts that do:

trap cmd 0 1 2 3 13 15 # EXIT HUP INT QUIT PIPE TERM

In every shell I have access to at the moment, all the traps oth

3条回答
  •  暖寄归人
    2021-02-02 08:07

    The shell standard does not specify whether a trap on 0 is executed when an untrapped signal is received. In particular, bash and dash behave differently. Given trap cmd-list 0 with no traps set for any signals, bash will execute the cmd-list upon receipt of SIGTERM, but dash will not. Given trap cmd-list 0 2, bash executes cmd-list once upon receipt of SIGTERM, and dash executes cmd-list twice.

提交回复
热议问题