Discussion:
How to not to trap RETURN at `source`?
(too old to reply)
Peng Yu
2018-12-05 21:19:26 UTC
Permalink
Hi,

I'd like to not to trap RETURN at `source`. However, the only
difference between them is $_, which cannot be used to tell the
difference on whether the trap is from a function return or a source
return. Is there any other way to just not to trap on source returns
but trap on function returns?

$ ./main.sh
123abc78,79c78,79
< _=3
< i=1
---
_=c
i=2
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

tmpdir=$(mktemp -d)
function f {
local i=0
trap '((++i)); declare > "$tmpdir/$i.txt"' RETURN
printf '%s' {1..3} >&2
source <(:)
printf '%s' a b c >&2
}

f

cd "$tmpdir"
diff 1.txt 2.txt
--
Regards,
Peng
Loading...