Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Function-scoped parameters?
- X-seq: zsh-users 15826
- From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Function-scoped parameters?
- Date: Wed, 23 Feb 2011 16:27:22 -0500 (EST)
- Cc: Zsh Users <zsh-users@xxxxxxx>
- In-reply-to: <AANLkTi=tPgwaene4RU8os41oTU=cFWQcrFHJW=9ferNr@mail.gmail.com>
- 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
- References: <alpine.LNX.2.01.1102231257420.2792@hp> <AANLkTi=tPgwaene4RU8os41oTU=cFWQcrFHJW=9ferNr@mail.gmail.com>
On Wed, 23 Feb 2011, Bart Schaefer wrote:
On Wednesday, February 23, 2011, Benjamin R. Haskell <zsh@xxxxxxxxxx> wrote:
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.
That's what "always" is for.
dosomething() {
emulate -L zsh
local temp=$(mktemp)
setopt err_return
{
# ...
} always {
(( $+temp )) && rm $temp
}
}
... Whoa. ...
Still wondering what other shells do, but man, I love Zsh.
--
Best,
Ben
Messages sorted by:
Reverse Date,
Date,
Thread,
Author