Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: path PATH
On Tue, Jan 24, 2023 at 12:00 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> > set -- ${(ok)parameters[(I)${~${(j.|.)@}}]}
$parameters is an associative array, so you can subscript it with [ ]
to get the elements. The keys of this array are parameter names.
${(.|.)var} means to join an array with vertical bars; here the var is
@ for the positional parameters.
${~something} means the value of something can be treated as a
pattern, so the |-joined positional parameters form a pattern.
(I) in an associative array subscript means to return every element
whose key matches a pattern, so instead of getting just one element it
is an array of elements.
(k) prefixing an associative array reference means to return the keys
(normally the values would be returned), so now we have an array of
parameter names.
(o) prefixing any array reference means to sort ("order") the results,
so we get the matching parameter names in alphabetical order.
"set --" replaces the original positional parameters with this array
of parameter names.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author