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

Re: Simplest way to choose one of several commands



On Mon, 07 Sep 2009 15:32:50 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> } Side note, I would have expected $commands[(K)(ls|cat)] to list
> } /bin/ls and /bin/cat, but it doesn't (it's empty).
> 
> That does seem odd, but you can get it with ${(v)commands[(I)(ls|cat)]}.

They're different.  (K) treats the *keys* as patterns (there's a clue
there), and matches them against the index argument.

% typeset -A foo         
% foo=('(ls|gls)' "This is the one you want")
% print ${foo[(K)ls]}                    
This is the one you want

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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