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

Re: 'K' subscript flag with associative array?



On 1 March 2011 17:50, Greg Klanderman <gak@xxxxxxxxxxxxxx> wrote:
>
> Hi guys, what am I doing wrong here?  Shouldn't this:
>
>  zsh% echo ${(k)functions[(K)_*]}
>
> give all function names starting with '_'?
>
> It gives me nothing; the 'R' subscript flag does seem
> to work for matching against the bodies of functions
> and returning the names of those functions.
>
> thanks,
> Greg
>

% echo ${(k)functions[(<tab>
---- subscript flags
I  -- all keys matched by subscript as pattern
K  -- all values where subscript matched by key as pattern
R  -- all values matched by subscript as pattern
e  -- interpret * or @ as a single key
i  -- any one key matched by subscript as pattern
k  -- any one value where subscript matched by key as pattern
r  -- any one value matched by subscript as pattern

Ie, you want I, not K. What K/k does is somewhat weird, in that it
interprets the keys of the arrays as patterns and check which of those
match the given subscript. With I/i you don't need to specify ${(k)
either, it defaults to showing the keys, but you can give ${(v) to
instead get the values.

-- 
Mikael Magnusson



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