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

Re: Simplest way to choose one of several commands



On Sep 7, 11:49pm, Mikael Magnusson wrote:
}
} Some meandering through the man page later:
} % echo ${${:-$commands[(R)*/(ls|cat)]}[1]}
} /bin/ls
} % echo ${${:-$commands[(R)*/(ls|cat)]}[2]}
} /bin/cat

I'm not certain that the results are guaranteed to be in the order
that words appear in the (...|...) expression.  $commands is a hash 
table so I believe the order is going to be unspecified.
 
} 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)]}.



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