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

Re: How to clean up path most efficiently?

Timothy Luoma wrote:
> > It should be as simple as:
> > 
> > path=($^path(N))
> Does that go through the current $PATH and delete all the folders that
> aren't listed in there?

I should probably have explained in more detail at the time.

The ^ indicates that anything outside the array should be expanded with
each element, so the expression becomes something like:

path=(/usr/local/bin(N) //usr/nonexistent/bin(N) /usr/bin(N) /bin(N))

The presence of the glob qualifier (N) turns on globbing even though
there are no patterns present (historically, it didn't always do that).
The shell then goes through it turning any name which doesn't exist in the
filesystem into a null string, and passing the rest through, so it
becomes something like:

path=(/usr/local/bin /usr/bin bin)

which then gets assigned back to path.  This automatically appears in


Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.


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