Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Two simple questions
- X-seq: zsh-users 7998
 
- From: Stephane Chazelas <Stephane.Chazelas@xxxxxxxxx>
 
- To: zsh-users@xxxxxxxxxx
 
- Subject: Re: Two simple questions
 
- Date: Wed, 15 Sep 2004 11:29:52 +0100
 
- Cc: Tero Niemela <tero_niemela@xxxxxxxxx>
 
- In-reply-to: <20040915083655.GA1180@DervishD>
 
- Mail-followup-to: zsh-users@xxxxxxxxxx,	Tero Niemela <tero_niemela@xxxxxxxxx>
 
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
 
- References: <20040914190916.GA974@DervishD> <20040915051128.66457.qmail@xxxxxxxxxxxxxxxxxxxxxxx> <20040915083655.GA1180@DervishD>
 
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