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

Re: Two simple questions



On Wed, Sep 15, 2004 at 10:36:56AM +0200, DervishD wrote:
[...]
> > > > path=($^path(N))
> > > > manpath=($^manpath(N)) 
[...]
>     Very clever! :) The '^' makes the '(N)' glob qualifier to be
> added to each element of the array :)) Thanks a lot for the
> explanation, is a very clever way of removing non-existent dirs from
> a list (well, an array in this case).
[...]

All the given solutions seem to forget about one thing about
$PATH. An empty element in it means "current directory".

$path instead of "$path[@]" removes the empty components in it.
That doesn't apply to $^path, though, but to the other
solutions.

$ echo $PATH
/usr/xpg4/bin:/usr/bin:/usr/local/bin:
$ print -rl $path
/usr/xpg4/bin
/usr/bin
/usr/local/bin
$ print -rl "$path[@]"
/usr/xpg4/bin
/usr/bin
/usr/local/bin

$ print -rl ${^path}(N)
/usr/xpg4/bin
/usr/bin
/usr/local/bin
$ 

You can change "" to "." with ${path/(#s)(#e)/.}
but that's slightly different.

$ PATH=/::/bin://bin/
$ print -rl ${(u)${${path/(#s)(#e)/.}//\/##/\/}/(#b)(?)\/(#e)/$match}
/
.
/bin
$ 

(note that ${path/%\//} changes "/" into "".

-- 
Stephane



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