Yes, you can capture RETURN:
$ function foo() {
> trap "echo finished" RETURN
> echo "doing some things"
> }
$ foo
Will display
doing some things
finished
From the man bashdescription of trapbuiltin:
If sigspec is RETURN, the arg command is executed every time a shell or script function is executed that is executed with. or inline source functions complete execution.
Aaron source
share