zsh-users
 help / color / mirror / code / Atom feed
* Removing an element from an array
@ 2020-11-02 11:11 Peter Slížik
  2020-11-02 11:25 ` Roman Perepelitsa
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Slížik @ 2020-11-02 11:11 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1028 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1514 bytes --]

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

end of thread, other threads:[~2020-11-02 18:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 11:11 Removing an element from an array Peter Slížik
2020-11-02 11:25 ` Roman Perepelitsa
2020-11-02 12:23   ` Peter Slížik
2020-11-02 18:31     ` 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).