Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Function-scoped parameters?
- X-seq: zsh-users 15821
- From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Function-scoped parameters?
- Date: Wed, 23 Feb 2011 13:03:20 -0500 (EST)
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author