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

path and += troubles

Hi all,

OK after reading the FAQ completely I am at my wits end. I want to create three basic functions dealing with arrays
		- Append
		- Prepend
		- Delete
The basic usage would be something along the lines of let's say I had this nice array called path which looked like this:
	echo $path
		/usr/sbin	/bin	/foo	/usr/local/bin

Then I did ran a couple of functions..
		appendPath  path /bin
		prependPath path /sbin
		deletePath path /foo

and ended up with...

	echo $path
		/sbin /usr/sbin /usr/local/bin /bin

My basic functions would be:

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

	deletePath () {
# I cannot take credit for this - Borrowed from the net - but it works :)
		# I couldn't figure out how to use ${var#del}
		local element
  		local build
  		eval '
  			foreach element in "$'"$1"'[@]"
    				if [[ -d "$element" && "$element" != $2 ]]
      					build=("$build[@]" "$element")
  			'"$1"'=( "$build[@]" )

But THIS DOESN"T WORK!!! IT Should!! According to the FAQ += should add the path to the array. Can someone help me with 2 things.
	1.  Why does += not work when adding to the array - It should right?
	2.  How will I handle prepend - I need to do a shift of all array items

Comments welcome thanks!!


Steven Klass

(480) 988-5657

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