zsh-users
 help / color / mirror / code / Atom feed
* path and += troubles
@ 2005-11-26  4:32 Steven Klass
  2005-11-26  9:32 ` Christian Taylor
  2005-11-26 17:00 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Steven Klass @ 2005-11-26  4:32 UTC (permalink / raw)
  To: zsh-users

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@pointcircle.com
(480) 988-5657


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-11-27  1:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-26  4:32 path and += troubles Steven Klass
2005-11-26  9:32 ` Christian Taylor
2005-11-26 13:25   ` Vincent Lefevre
2005-11-26 14:54     ` Steven Klass
2005-11-27  1:30       ` Vincent Lefevre
2005-11-26 17:00 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).