From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18419 invoked by alias); 29 Jul 2011 01:28:49 -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: 16152 Received: (qmail 3679 invoked from network); 29 Jul 2011 01:28:38 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:from:reply-to:to:date:in-reply-to:references:content-type :x-mailer:content-transfer-encoding:message-id:mime-version; bh=KKEqkIheIp3h1BPyOboou7OFDTe/Ov/pRiLWKBWsfAg=; b=IqjiLjgc+WApK43eywAlDijpa1C9WtgEk4OD2M6UMcsCXMQ1YVC7lR2XoNS6NJq25I Kk2bUAT9byisVAK7aijk4yM+QyQULS92E2i63kvfbl+bfCfTFI+nWcVxvuhXTIu6t5PB 3UEER8lC1JtuFxp2THj0sHy5x5FDiv/eOTKeY= Subject: Re: how to refer to basename of $0 From: Tomasz Moskal Reply-To: ramshackle.industries@gmail.com To: zsh-users@zsh.org Date: Fri, 29 Jul 2011 02:30:02 +0100 In-Reply-To: <20110729002402.GA41738@redoubt.spodhuis.org> References: <20110729002402.GA41738@redoubt.spodhuis.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.2 Content-Transfer-Encoding: 7bit Message-ID: <1311903004.7733.0.camel@localhost.localdomain> Mime-Version: 1.0 On Thu, 2011-07-28 at 20:24 -0400, Phil Pennock wrote: > On 2011-07-28 at 18:55 -0400, TJ Luoma wrote: > > the script "foo.sh" read .source like this: > > > > . $HOME/.source > > > > and then I did > > > > echo "$NAME" > > > > it would give me > > > > foo.sh > > > > but in zsh I get > > > > zsh > > Are you sure? > > % cat -v foo > . $HOME/bar > % cat -v bar > echo $0 > % zsh -f foo > /home/me/bar > % bash foo > foo > > The point is that in bash, sourcing a script does not change $0 while in > zsh it does by default, because FUNCTION_ARGZERO is set. > > % cat -v foo2 > unsetopt function_argzero > . $HOME/bar > % zsh -f foo2 > foo2 > > If you want to be portable to both bash and zsh, then: > > [[ -n $ZSH_VERSION ]] && unsetopt function_argzero > > This does, unfortunately, have to be done in the script which does the > including, so you can't have a common library used by both shells which > assumes that $0 is the name of the original file and which can just be > simply included. > > -Phil Damn, I was too late :-)