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

Removing an element from an array




Hello,

I would like to remove an element from an array - actually a path from the $path variable. After some googling, I've discovered the ${array:|excl} syntax.

Here is my code:

excl=($path_to_remove)
echo "path type: ${(t)path}
# -> path type: array-tied-export-special

export path=${path:|excl}
# -> export:19: path: inconsistent type for assignment

What am I doing wrong? Actually, as the command ends up with an exception, I'm not able to verify whether 'path' is an array or a scalar after the command.

This is the relevant part of the documentation. I don't think any of the conditions in the second sentence is relevant to the error message.

${name:|arrayname}

If arrayname is the name (N.B., not contents) of an array variable, then any elements contained in arrayname are removed from the substitution of name. If the substitution is scalar, either because name is a scalar variable or the _expression_ is quoted, the elements of arrayname are instead tested against the entire _expression_

Any suggestions?
Peter


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