help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] How to not to trap RETURN at `source`?


From: Peng Yu
Subject: [Help-bash] How to not to trap RETURN at `source`?
Date: Wed, 5 Dec 2018 15:19:26 -0600

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]