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

Re: for syntax differences from ksh



Sweth Chandramouli wrote:
>	i wrote the following function in ksh to easily add directories 
>to my path.  it worked fine there, but when i try to use it in zsh, it fails.
>
>addpath () {
>for pathdir in $*; do
>   if test -d $pathdir; then
>      PATH=$PATH:$pathdir
>   fi;
>done
>}

This function is correct for zsh.

>         (actually, the line is
>addpath $pathlist
>where pathlist is defined as the list of dirs, separated by spaces)

There's your problem.  By default, zsh does not perform field splitting on
the result of parameter substitution.  There are three possible solutions.
First, you can set the option SH_WORD_SPLIT, making zsh act like sh/ksh
in this regard.  Second, you could set that option for just the one
substitution, by rewriting it as `$=pathlist'.  The best solution would
be to use an array variable, which will allow you to handle pathnames
containing whitespace.

-zefram



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