From: "Peter Slížik" <peter.slizik@gmail.com>
To: zsh-users@zsh.org
Subject: Removing an element from an array
Date: Mon, 2 Nov 2020 12:11:12 +0100 [thread overview]
Message-ID: <CAC-uhUCeckrWr-F-hsXtktYO8G8Ts1=Opyg4S0Xb9Y4bMKnCKg@mail.gmail.com> (raw)
[-- 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 --]
next reply other threads:[~2020-11-02 11:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-02 11:11 Peter Slížik [this message]
2020-11-02 11:25 ` Roman Perepelitsa
2020-11-02 12:23 ` Peter Slížik
2020-11-02 18:31 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAC-uhUCeckrWr-F-hsXtktYO8G8Ts1=Opyg4S0Xb9Y4bMKnCKg@mail.gmail.com' \
--to=peter.slizik@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).