Many examples for trap use trap ... INT TERM EXIT for cleanup tasks. But is it really necessary to list all the three sigspecs?The manual says:If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from the shell.which I believe applies whether the script finished normally or it finished because it received SIGINT or SIGTERM. An experiment also confirms my belief:$ cat ./trap-exit#!/bin/bashtrap 'echo TRAP' EXITsleep 3$ ./trap-exit & sleep 1; kill -INT %1[1] 759TRAP[1]+  Interrupt               ./trap-exit$ ./trap-exit & sleep 1; kill -TERM %1[1] 773TRAP[1]+  Terminated              ./trap-exitThen why do so many examples list all of INT TERM EXIT? Or did I miss something and is there any case where a sole EXIT would miss?
trap ... INT TERM EXIT really necessary?
bash;shell;signals;trap
The POSIX spec doesn't say much about the conditions resulting in executing the EXIT trap, only about what its environment must look like when it is executed.In Busybox's ash shell, your trap-exit test does not echo 'TRAP' before exiting due to either SIGINT or SIGTERM. I would suspect there are other shells in existance that may not work that way as well.# /tmp/test.sh & sleep 1; kill -INT %1# [1]+  Interrupt                  /tmp/test.sh# # # /tmp/test.sh & sleep 1; kill -TERM %1# [1]+  Terminated                 /tmp/test.sh# 