From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28455 invoked by alias); 29 Jul 2011 00:39:57 -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: 16150 Received: (qmail 2281 invoked from network); 29 Jul 2011 00:39:45 -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=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at spodhuis.org does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201107; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=5Ah3ea7CP50jHDgjFtB87beQXLwii6NKuLjK2asabtA=; b=qim8IwKDPYLRTNbRnpf1nWoDxWyuKq0BQNJ+kH1UQ0VTRLPR/ROeNZBILFF1yoPMLkJRfkqihNnhwOcvCdskGKysXbfSe9yfTB20zL/cMgNS+TjtOvzOMxfFDFSNsANh4NbX9cWiO8Vqu2zhzGjrhzzxdOs+PAr5YKr6Kq9ooKI=; Date: Thu, 28 Jul 2011 20:24:02 -0400 From: Phil Pennock To: TJ Luoma Cc: Zsh Users Subject: Re: how to refer to basename of $0 Message-ID: <20110729002402.GA41738@redoubt.spodhuis.org> Mail-Followup-To: TJ Luoma , Zsh Users References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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