Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to refer to basename of $0
- X-seq: zsh-users 16154
- From: Tomasz Moskal <ramshackle.industries@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: how to refer to basename of $0
- Date: Fri, 29 Jul 2011 03:06:49 +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=hJeACGqz2jL9oNodwRq2Kj7Cd+/m/QnDZHiYjsrme2Q=; b=Sv3svdS1e9XSFkwNHJjcuYzbRpJB4O6hmnF+krx+vH6r5W3ozgo5b0Aluudv7t9gPR yOnPSZPjK/ka6XJKNjTwD4V3zdsyLU92OMqiL5FCyP+69G+rGcWcwcou/k0Voy1CmbDS mSE84jio5fvq78cMjxo71u5DF0kaCM1W5JP00=
- In-reply-to: <CADjGqHt4-PnBNC0QgyRVw0H-HtCWcRp_aA7N3zJoH+xK_676kw@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>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHuKhx9A3HCUBjU4JgRsbj52s7DQ6HGewT=Y9uRMDGD-fg@mail.gmail.com> <alpine.LNX.2.01.1107282034110.18508@hp.internal> <CADjGqHt4-PnBNC0QgyRVw0H-HtCWcRp_aA7N3zJoH+xK_676kw@mail.gmail.com>
- Reply-to: ramshackle.industries@xxxxxxxxx
On Thu, 2011-07-28 at 21:39 -0400, TJ Luoma wrote:
> Sorry folks, I'm explaining this really badly. Forget I said anything
> about bash. I don't care about bash. I'm trying to leave bash behind.
>
> Let me start over. Here's what happens in zsh 4.3.11
>
> # my comments are offset with #
> # fyi - "Air%" is my prompt
>
> # just to show that $NAME is empty
> Air% echo $NAME
> Air%
>
>
> # /tmp/.source has only one line:
> Air% cat /tmp/.source
> NAME=`basename $0`
>
> # here is my 'test.zsh' script:
> Air% cat ./test.zsh
> #!/bin/zsh
>
> . /tmp/.source
>
> echo "$NAME"
>
> exit 0
>
> # So now I run 'test.zsh' :
>
> Air% ./test.zsh
> .source
>
> # OK, so you can see that it output '.source' when I wanted it to
> output 'test.zsh'
>
> # Next: rename /tmp/.source to ~/.zshenv
>
> Air% mv /tmp/.source ~/.zshenv
>
> # Edited 'test.zsh' is now this:
>
> Air% cat =test.zsh
> #!/bin/zsh
>
> echo "$NAME"
>
> exit 0
> #EOF
>
> # now when I run 'test.zsh' again:
>
> Air% test.zsh
> zsh
>
> # Someone suggested "unsetopt function_argzero" so I added that to .zshenv:
>
> Air% cat ~/.zshenv
> unsetopt function_argzero
>
> NAME=`basename $0`
>
> # and re-ran test.zsh, which gave me:
>
> zsh
>
>
> Is it even possible to set NAME in .zsh* (and have it return
> 'test.zsh' or are they called too early in the process?
>
> TjL
It's working here:
% cat .zshenv
unsetopt function_argzero
name=`basename $0`
% cat foo
#!/bin/zsh
. ~/.zshenv
echo $name
exit 0
% ./foo
foo
A bit perplexed, this is what I am... Have a look at this:
% zsh -f
% ./foo
foo
Messages sorted by:
Reverse Date,
Date,
Thread,
Author