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..
		$1+=($2)
	}

	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
  		build=()
  		eval '
  			foreach element in "$'"$1"'[@]"
  			do
    				if [[ -d "$element" && "$element" != $2 ]]
    				then
      					build=("$build[@]" "$element")
    				fi
  			done
  			'"$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

sklass@xxxxxxxxxxxxxxx
(480) 988-5657



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