* [BUG] Trap and local variable
@ 2015-10-11 21:01 Sebastian Gniazdowski
2015-10-11 21:32 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2015-10-11 21:01 UTC (permalink / raw)
To: zsh-workers
Hello,
following code:
b() { integer locl=1337; globl=2337; a() { echo "$locl, $globl"; };
trap "a" EXIT }; b
outputs only 2337. If one tries this first:
integer locl=1337; globl=2337; a() { echo "$locl, $globl"; }; b() {
trap "a" EXIT }; b
then the previous version will also work fine.
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [BUG] Trap and local variable
2015-10-11 21:01 [BUG] Trap and local variable Sebastian Gniazdowski
@ 2015-10-11 21:32 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2015-10-11 21:32 UTC (permalink / raw)
To: zsh-workers
On Oct 11, 11:01pm, Sebastian Gniazdowski wrote:
} Subject: [BUG] Trap and local variable
}
} Hello,
} following code:
}
} b() { integer locl=1337; globl=2337; a() { echo "$locl, $globl"; };
} trap "a" EXIT }; b
}
} outputs only 2337.
This isn't a bug.
Function definitions don't nest, so even though you didn't define "a"
until inside of "b", the scope of "a" is a sibling of "b". Also, the
doc for the "trap" command says:
If SIG is 0 or EXIT and the trap statement is executed inside the
body of a function, then the command ARG is executed after the
function completes.
So $locl is already out of scope when the trap runs, there is no way
for "a" to see it.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-11 21:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-11 21:01 [BUG] Trap and local variable Sebastian Gniazdowski
2015-10-11 21:32 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).