zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: "Peter Slížik" <peter.slizik@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Removing an element from an array
Date: Mon, 2 Nov 2020 12:25:21 +0100	[thread overview]
Message-ID: <CAN=4vMoAcip8q_zTm1-R-81d15OP9o6_Gyu7cvcpdbE-BLScVg@mail.gmail.com> (raw)
In-Reply-To: <CAC-uhUCeckrWr-F-hsXtktYO8G8Ts1=Opyg4S0Xb9Y4bMKnCKg@mail.gmail.com>

On Mon, Nov 2, 2020 at 12:11 PM Peter Slížik <peter.slizik@gmail.com> wrote:
>
> 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)
> export path=${path:|excl}

This is pretty close. Here's the correct syntax:

    excl=($path_to_remove)
    path=(${path:|excl})

However, if you want to remove just one element, there is a simpler way:

    path=(${path:#$path_to_remove})

Roman.


  reply	other threads:[~2020-11-02 11:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 11:11 Peter Slížik
2020-11-02 11:25 ` Roman Perepelitsa [this message]
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='CAN=4vMoAcip8q_zTm1-R-81d15OP9o6_Gyu7cvcpdbE-BLScVg@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=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).