zsh-users
 help / color / mirror / code / Atom feed
* Function-scoped parameters?
@ 2011-02-23 18:03 Benjamin R. Haskell
  2011-02-23 18:27 ` Benjamin R. Haskell
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Benjamin R. Haskell @ 2011-02-23 18:03 UTC (permalink / raw)
  To: Zsh Users

This doesn't work, probably unsurprisingly.  But is there a way to 
accomplish it?

function () {
     emulate -L zsh
     local x=asdf
     trap 'echo x is ${x:-unset}' EXIT
}

The use case is that I want to assign a local parameter 'temp' to 
be set to the name of a temporary file.  If anything goes wrong in the 
function, I'd like that temporary file to be removed, but I don't want 
'temp' to leak out of the function scope.

e.g.:
dosomething () {
     emulate -L zsh
     local temp=$(mktemp)
     setopt err_return
     trap '(( $+temp )) && rm $temp' EXIT
     # ...
}

-- 
Best,
Ben


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

end of thread, other threads:[~2011-02-23 21:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-23 18:03 Function-scoped parameters? Benjamin R. Haskell
2011-02-23 18:27 ` Benjamin R. Haskell
2011-02-23 19:17 ` Sebastian Stark
2011-02-23 20:01   ` Benjamin R. Haskell
2011-02-23 20:29 ` Bart Schaefer
2011-02-23 21:27   ` Benjamin R. Haskell

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