Huh, no mention of "set -e -u"?
Do yourself a favor and follow this, too:
http://www.davidpashley.com/articles/writing-robust-shell-sc...
Regarding traps, I struggled for a while with getting a robust and simple way to kill backgrounded scripts on exit. I would have a script do stuff like "sort bigfile & pid=$!; runlongtask; wait $pid", and on Ctrl-C I wanted the sort command to stop too. The trick is to use "kill 0", which kills the non-interactive script and its subprocesses (see "man 2 kill"). So say you want to both remove some temp directory and kill all subprocesses on Ctrl-C, put this at the top of your script:
trap 'rm -rf "$tmp"; kill 0' EXIT
Usually, you never want your script to continue running after a command unexpectedly fails or you use an unset variable. Saves so much time debugging!