From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10501 invoked by alias); 3 Jun 2014 20:15:42 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32683 Received: (qmail 27580 invoked from network); 3 Jun 2014 20:15:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.2 X-Submitted: to socket.bbn.com (Postfix) with ESMTPSA id 472774088C Message-ID: <538E2CDD.7070106@bbn.com> Date: Tue, 03 Jun 2014 16:15:25 -0400 From: Richard Hansen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Bart Schaefer CC: zsh-workers@zsh.org Subject: Re: 'emulate sh -c' and $0 References: <5387BD0D.8090202@bbn.com> <140529204533.ZM5362@torch.brasslantern.com> <5388461D.8060203@bbn.com> <140530100050.ZM18382@torch.brasslantern.com> <5388F4C3.6070801@bbn.com> <140530221301.ZM31798@torch.brasslantern.com> In-Reply-To: <140530221301.ZM31798@torch.brasslantern.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 2014-05-31 01:13, Bart Schaefer wrote: > If we leave FUNCTION_ARGZERO as it is (that is, off by default for sh > emulation) and add an option POSIX_ARGZERO which exposes the global > argzero when set (inverting your Option #2) but which is never on by > default, then bin_emulate can set POSIX_ARGZERO in the -c scope when > emulating sh/ksh, and it will be sticky for functions defined there. > > We wouldn't even have to build those smarts into bin_emulate; a user > who wanted the POSIX semantics could explicitly do > > emulate sh -o POSIX_ARGZERO -c '...' > > The only "magic" necessary is that POSIX_ARGZERO exposes the original > value of $0 in spite of the current FUNCTION_ARGZERO setting. > > Here are the bits outside bin_emulate, and not yet with doc. I suppose > there may be some places where posixzero needs to be saved / changed / > restored, which this hasn't covered. Wow, thank you for committing this change to master! It works well in my limited testing, except for the documented limitation that POSIX_ARGZERO stays enabled when calling a non-emulated function from a function defined in 'emulate -c'. I'm not sure how much this will matter in practice, but if backward compatibility wasn't a concern it'd be nice if zsh temporarily restored options when invoking a function outside the 'emulate -c' boundary. Although it would be a behavior change, I think it would be best if both 'emulate sh' and 'emulate sh -c' set POSIX_ARGZERO by default: I suspect that someone who runs 'emulate sh' cares more about accurate sh emulation than compatibility with previous sh emulation behavior. :) Thanks, Richard