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

Re: Removing an element from an array



On Mon, Nov 2, 2020 at 12:11 PM Peter Slížik <peter.slizik@xxxxxxxxx> 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.




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