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

Re: path and += troubles



On Nov 25,  9:32pm, Steven Klass wrote:
}
} 		# Append the path to the end..
} 		$1+=($2)

As you've discovered, this won't work.  $1 is not an identifier (it's an
identifier dereference) so $1+= is not an assignment.  Of course, you
need to have a recent-enough version of zsh to support += assignments.

For some reason "setopt nullglob" (even cshnullglob) prevents the error
message that would otherwise be produced for this line, turning it into
a silent no-op.  I think that's probably an obscure bug.

Anyway, what you need is something like

		eval $1'+=( $2 )'

} 		# I couldn't figure out how to use ${var#del}

That's probably because it's ${var:#del}.

		eval $1'=( ${(P)1:#$2} )'

} 	2.  How will I handle prepend - I need to do a shift

		eval $1'=( $2 ${(P)1} )'

or (better only for really huge arrays, and watch out for the ksharrays
setopt which changes the subscript offset):

		eval $1'[1]=( $2 ${${(P)1}[1]} )'

You're probably better off doing everything in one assignment rather than
by having appendPath call deletePath.  E.g.

    appendElem() { eval $1'+=( $2 )' }
    prependElem() { eval $1'=( $2 ${(P)1} )' }
    deleteElem() {  eval $1'=( ${(P)1:#$2} )' }
    appendUniq() { eval $1'=( ${(P)1:#$2} $2 )' }
    prependUniq() { eval $1'=( $2 ${(P)1:#$2} )' }



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