@simon same idea but trap functionname EXIT, and it will run on any non sigkill exit