zsh-users
 help / color / mirror / code / Atom feed
* trap question
@ 2022-11-25 18:35 Ray Andrews
  2022-11-25 18:57 ` Roman Perepelitsa
  0 siblings, 1 reply; 11+ messages in thread
From: Ray Andrews @ 2022-11-25 18:35 UTC (permalink / raw)
  To: Zsh Users

This script:

typeset -g var=0
test1 ()
{
trap " [[ $var == '0' ]] && echo trap: var is: $var" EXIT
var=0
return
}
test2 ()
{
var=1
test1
echo "test2: var is: $var"
}

run:

$ . test1; test1; test2
trap: var is: 0
test2: 0

... I'm puzzled, even tho test2 does reset the variable to '1', test1 
sets it back to '0' just as the final 'echo' reports so I'm expecting 
the trap to spring.  Foolishly since that's C thinking whereas in 
interpreted code the value of the variable *at the time of the 
definition of the trap* is what is in effect and in this case that's 
'1'.  So what I'm really wanting is some way to set the trap in such a 
way that it responds to the value of 'var' *at the time of the springing 
of the trap*, namely at 'return'.  Can it be done?



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-11-27  1:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 18:35 trap question Ray Andrews
2022-11-25 18:57 ` Roman Perepelitsa
2022-11-25 23:25   ` Ray Andrews
2022-11-26  1:57     ` Bart Schaefer
2022-11-26  4:25       ` Philippe Altherr
2022-11-26  4:27       ` Ray Andrews
2022-11-26  4:49         ` Lawrence Velázquez
2022-11-26  4:50         ` Bart Schaefer
2022-11-26 15:03           ` Ray Andrews
2022-11-26 15:25             ` Roman Perepelitsa
2022-11-27  1:49               ` Ray Andrews

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).