Hi guys,

    Yes, it happened again. The latest version of zsh breaks the
append_path() and prepend_path() functions in the /sw/bin/init.sh script.
They still add elements to the path but they always do it, even if there is
duplication. This means that the elaborate "if" statements always evaluate
to true.

    Zsh is constantly making parameter expansion more elaborate. The goal
seems to be to implement the power of regular expressions with a syntax
compatible with filename globbing. They are constantly creating more and
more "metacharacters". Last time this happened I was able to fix it by
quoting the new metacharacters but this time I was unable to find the
offending characters. However, I finally gave up on that and figured out how
to get double quotes around the parameters at both stages of expansion in
the eval statement. Here are the functions that work properly in zsh:

# add to end of path
append_path()
{
  if ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z
"\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
    eval "$1=\$$1:$2"
  fi
}

# add to front of path
prepend_path()
{
  if ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z
"\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
    eval "$1=$2:\$$1"
  fi
}

The above functions also work correctly in bash.

    I have my own (stolen) version of these in my shell startup scripts and
in mine, I've added a check for existence of the path variable to the
beginning of the functions, like so:

# add to end of path
appendPath()
{
    if eval test -z \"\$$1\" ; then
        eval "$1=$2"
    elif ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z
"\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
        eval "$1=\$$1:$2"
    fi
}

While it doesn't really change the number of tests performed, it eliminates
the need to write a check for existence before each use of these functions.
Thus, it would greatly simplify the writing and maintenance of the init.sh
script. This could also be done in the init.csh script.

    I'm sorry for sending this to the list but I don't know who "maintains"
these files. My impression from the lists I'm on is that the number of zsh
users is growing so hopefully you can get these into the Fink distribution.
If course my "estimate" of the number of zsh and Fink users is tainted by
the fact that I plug both every chance I get. :-) However, they really are
the best, right? Thanks for "making it so"!
-- 
Gary
~~~~
There are only 10 kinds of people in the world. Those who understand binary
numbers and those who don't.



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Fink-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/fink-devel

Reply via email to