I want to do sth. like this:
foo=(a b c)
foo-=b
echo $foo # should output "a c"
How can I remove an entry from an array? foo-=b does not work.
The removal should work no matter where the entry is.
I want to do sth. like this:
foo=(a b c)
foo-=b
echo $foo # should output "a c"
How can I remove an entry from an array? foo-=b does not work.
The removal should work no matter where the entry is.
Since versions 4.2 and 5.0, zsh accepts ${name:|arrayname} syntax. From manual:
If
arraynameis the name (N.B., not contents) of an array variable, then any elements contained inarraynameare removed from the substitution ofname.
So, it does exactly what you expect:
$ foo=(a b c)
$ excl=(b)
$ echo ${foo:|excl}
a c