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

Re: Removing an element from an array



Dear Roman,

thank you for both suggestions.

By the way,  can I ask why it is necessary to re-introduce the array context by another pair of parentheses, if the _expression_ already produces an array value?

Or does the ${...:|...} _expression_ produce a string which needs to be parsed again? Would this cause problems if any of the path elements contained a space in the file name?

Thank you,
Peter

пон, 2. нов 2020. у 12:25 Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> је написао/ла:
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