Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH_SCRIPT



On Wed, 2 Mar 2016 16:24:13 -0500
Greg Klanderman <gak@xxxxxxxxxxxxxx> wrote:
> >>>>> On March 2, 2016 Martijn Dekker <martijn@xxxxxxxx> wrote:
> 
> > Is there a particular reason why it should be empty rather than unset?
> > Unset seems more logical; if we're not running a script, the script name
> > is not the empty string but it doesn't exist. This would also make it
> > possible to do
> > 	[[ -v ZSH_SCRIPT ]]
> > to check if you're in a script.
> 
> Hi Martijn, I'm happy to do it either way, but went with what had
> been discussed about 5 years ago when both Bart and Peter seemed to
> prefer empty to unset:
> 
> http://www.zsh.org/mla/workers/2011/msg00183.html
> 
> Bart> I think empty is OK, but let's hear from PWS.
> 
> PWS> I think empty is much more Zen-like, so fits perfectly.
> 
> Bart and Peter, can you let me know if that still holds?

I don't think we ever had a major preference.

The only real objection to it being unset is an error is if you test

[[ -z $ZSH_SCRIPT ]]

and NO_UNSET is set.  This is much more likely for a zsh programmer than
the rarely used -v.  On the other hand, ${+ZSH_SCRIPT} is a standard zsh
idiom which is quite widely used.  However, as it's a new variable, it
really doesn't matter that much as long as it's documented.

There's a rather minor objection that if it's not set in a shell
function you might think the shell never sets it and use it yourself.
But programming by assumption isn't very healthy.

I can't think of anything else.  So I really don't think it makes a lot
of difference.

pws



Messages sorted by: Reverse Date, Date, Thread, Author