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

Re: typeset -U and "special-ness"



Scott RoLanD wrote:
> I love 'typeset -U' for paramaters like PATH, MAILPATH, and
> MANPATH. However, I was disappointed to learn that 'typeset -U
> LD_LIBRARY_PATH' has no effect.
> 
> I understand that 'typeset -U' only works for "special" paramaters,
> but why? How did MANPATH get elevated to the status of a "special"
> paramater when it isn't used by the shell at all?

It was presumably just a random choice; at the time, MANPATH was much more
frequently used than LD_LIBRARY_PATH.

In the current development version, and so presumably in 3.1.6, you
are/will be able to do,
  typeset -TU LD_LIBRARY_PATH ld_library_path
to tie a colon-separated array to a shell array.  This will then work in
the same as special tied parameters, so the -U flag is useful even if you
never use $ld_library_path directly.  (It's too much work to eliminate the
real array.)  Arguably, we could then remove the specialness of MANPATH,
and just initialise it as an ordinary tied array which the user can then
unset if they want.

> Also, 'typeset -U' doesn't remove duplicates from current values of
> the paramaters. Any good reason for this?

You'll find it does if you turn on uniqueness for the array version of the
parameter, i.e. manpath instead of MANPATH.  I suppose this was just an
oversight.  The following patch makes it do the same when you use the
colon-array version of the parameter.

--- Src/builtin.c.uniq	Tue May 11 11:20:53 1999
+++ Src/builtin.c	Sun May 16 15:09:59 1999
@@ -1521,9 +1521,14 @@
 	    zerrnam(cname, "%s: restricted", pname, 0);
 	    return pm;
 	}
-	if (PM_TYPE(pm->flags) == PM_ARRAY && (on & PM_UNIQUE) &&
-	    !(pm->flags & PM_READONLY & ~off))
-	    uniqarray((*pm->gets.afn) (pm));
+	if ((on & PM_UNIQUE) && !(pm->flags & PM_READONLY & ~off)) {
+	    Param apm;
+	    if (PM_TYPE(pm->flags) == PM_ARRAY)
+		uniqarray((*pm->gets.afn) (pm));
+	    else if (PM_TYPE(pm->flags) == PM_SCALAR && pm->ename &&
+		     (apm = (Param) paramtab->getnode(paramtab, pm->ename)))
+		uniqarray((*apm->gets.afn) (apm));
+	}
 	pm->flags = (pm->flags | on) & ~off;
 	/* This auxlen/pm->ct stuff is a nasty hack. */
 	if ((on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z | PM_INTEGER)) &&

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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