2010/9/11 "Paweł Hajdan, Jr." <phajdan...@gentoo.org> > On 9/11/10 11:03 AM, Jonathan Callen wrote: > > Just as a proof-of-concept, here's one implementation of such a > > function, allowing for an arbitrary number of arguments: > > > > use_echo() { > > while [[ $# -gt 1 ]]; do > > if use "$1"; then > > echo "$2" > > return > > fi > > shift 2 > > done > > [[ $# -eq 1 ]] && echo "$1" > > } > > Looks good to me. If it doesn't get included in any eclass, I will just > paste it to the chromium ebuilds. :) > > Paweł > > I don't count but sometimes I do still read ebuilds, the function proposed look a bit^W unreadable to me, may I suggest to aggregate use and echo, separating them with a comma ",". The first element with an empty "use" always echo and return.
See implementation and example below use_case() { local u local c while [[ $# -gt 0 ]] do u=${1%%,*} c=${1#*,} if [[ ${u} == "" ]] || use $u then echo ${c} break fi shift done } echo $(use_case useA,echoA useB,echoB ,echoC)