I'm dabbling in traps in Bash again. I've just noticed the RETURN trap doesn't fire up for functions.
$ trap 'echo ok' RETURN
$ f () { echo ko; }
$ f
ko
$ . x
ok
$ cat x
$
As you can see it goes off as expected for sourcing the empty file x
.
Bash's man
has it so:
If a sigspec is RETURN, the command arg is executed each time a shell
function or a script executed with the . or source builtins finishes
executing.
What am I missing then?
I have GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu).
Best Answer
As I understand this, there's an exception to the doc snippet in my question. The snippet was:
The exception is described here:
As for
functrace
, it can be turned on with thetypeset
's-t
:Also
set -o functrace
does the trick.Here's an illustration.
As for
declare
, it's the-t
option again:Also
extdebug
enables function tracing, as in ikkachu's answer.