Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to refer to basename of $0
- X-seq: zsh-users 16150
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: TJ Luoma <luomat@xxxxxxxxx>
- Subject: Re: how to refer to basename of $0
- Date: Thu, 28 Jul 2011 20:24:02 -0400
- Cc: Zsh Users <zsh-users@xxxxxxx>
- 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=;
- In-reply-to: <CADjGqHuKhx9A3HCUBjU4JgRsbj52s7DQ6HGewT=Y9uRMDGD-fg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: TJ Luoma <luomat@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHuKhx9A3HCUBjU4JgRsbj52s7DQ6HGewT=Y9uRMDGD-fg@mail.gmail.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author