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

Re: path and += troubles



Hi,

This exposes one of my personal problems with typeset. If I really want a path appended typeset -U will drop the appended path, in favor of the path which already exists. So IMHO the only way to handle this properly is to
	
Normalize the new path ($2) - Remove any trailing slashes ensure no double-slashes Check to see if the new path exists in the old path array ($1) and delete it
	Append or Prepend the new path to the $1
	
Here's some of the cleanup stuff I read about in this list..
	path=($^path(N))
	setopt EXTENDED_GLOB
	path=(${${path//\/##/\/}%/})
	unsetopt EXTENDED_GLOB
	typeset -U path

But can anyone please explain my number 1 item - that is really annoying me..

	appendPath() {
		# if the path exists delete it..
		deletePath $1 $2
		# Append the path to the end..
		$1+=($2)
	}

	1.  Why does += not work when adding to the array - It should right?


---

Steven Klass

sklass@xxxxxxxxxxxxxxx
(480) 988-5657

On Nov 26, 2005, at 6:25 AM, Vincent Lefevre wrote:

On 2005-11-26 10:32:35 +0100, Christian Taylor wrote:
I never bothered about a deletion function, because I simply use:
typeset -U path
which will keep only the first occurence of any element.

But if a same path is written in two different ways, it doesn't
recognise it:

ay:~> echo $library_path
/home/lefevre/./lib /home/lefevre/./lib /home/lefevre/lib /usr/ local/gmp/lib
ay:~> typeset -U LIBRARY_PATH
ay:~> echo $library_path
/home/lefevre/./lib /home/lefevre/lib /usr/local/gmp/lib

--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/ blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA



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