From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28495 invoked by alias); 23 Feb 2011 20:01:39 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15823 Received: (qmail 7293 invoked from network); 23 Feb 2011 20:01:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Wed, 23 Feb 2011 15:01:09 -0500 (EST) From: "Benjamin R. Haskell" To: Sebastian Stark cc: Zsh Users Subject: Re: Function-scoped parameters? In-Reply-To: <36E878CD-45EF-4BDE-8F1A-601A5CFD1E37@biskalar.de> Message-ID: References: <36E878CD-45EF-4BDE-8F1A-601A5CFD1E37@biskalar.de> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed On Wed, 23 Feb 2011, Sebastian Stark wrote: > Am 23.02.2011 um 19:03 schrieb Benjamin R. Haskell: > >> 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 >> # ... >> } > > Would "setopt localtraps" be of any help? > >>From the documentation for 'emulate': [...] If the -L option is given, the options LOCAL_OPTIONS and LOCAL_TRAPS will be set as well[...] So, it's already set by `emulate -L zsh`. -- Best, Ben