zsh-users
 help / color / mirror / code / Atom feed
From: Tomasz Moskal <ramshackle.industries@gmail.com>
To: zsh-users@zsh.org
Subject: Re: how to refer to basename of $0
Date: Fri, 29 Jul 2011 02:30:02 +0100	[thread overview]
Message-ID: <1311903004.7733.0.camel@localhost.localdomain> (raw)
In-Reply-To: <20110729002402.GA41738@redoubt.spodhuis.org>



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 :-)


  reply	other threads:[~2011-07-29  1:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-28 22:55 TJ Luoma
2011-07-28 23:54 ` Tomasz Moskal
2011-07-29  0:24 ` Phil Pennock
2011-07-29  1:30   ` Tomasz Moskal [this message]
2011-07-29  0:44 ` Benjamin R. Haskell
2011-07-29  1:39   ` TJ Luoma
2011-07-29  2:06     ` Tomasz Moskal
2011-07-29  4:04     ` Bart Schaefer
2011-07-29  4:50       ` TJ Luoma
2011-07-29 11:48       ` Tomasz Moskal
2011-07-29 14:08         ` Benjamin R. Haskell
2011-07-29 22:30           ` Bart Schaefer
2011-07-30 19:43             ` Greg Klanderman
2011-07-29  3:05   ` TJ Luoma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311903004.7733.0.camel@localhost.localdomain \
    --to=ramshackle.industries@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).