Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to refer to basename of $0
- X-seq: zsh-users 16152
- From: Tomasz Moskal <ramshackle.industries@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: how to refer to basename of $0
- Date: Fri, 29 Jul 2011 02:30:02 +0100
- 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=
- In-reply-to: <20110729002402.GA41738@redoubt.spodhuis.org>
- 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: <CADjGqHuKhx9A3HCUBjU4JgRsbj52s7DQ6HGewT=Y9uRMDGD-fg@mail.gmail.com> <20110729002402.GA41738@redoubt.spodhuis.org>
- Reply-to: ramshackle.industries@xxxxxxxxx
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 :-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author