trap - shell sciprt で SIGNAL を trap

perlでは$SIG{INT} あたりにcoderef を設定すればいいけど、bash/zshではどうやるんだろうー。と悩んでman bash を見ていたらtrap という組み込みコマンドを発見。

trap [-lp] [[arg] sigspec ...]
    The  command arg is to be read and executed when the shell receives signal(s) sigspec.
$ trap date 2 

とすると、Ctrl-C を押してSIGINTを送るとdateコマンドが実行される。