#!/bin/bash trap '<some command>' EXIT #XXX of SIG_XXX <more commands> & #send to bg wait #wait bg commands