1 |
2010/9/11 "Paweł Hajdan, Jr." <phajdan.jr@g.o> |
2 |
|
3 |
> On 9/11/10 11:03 AM, Jonathan Callen wrote: |
4 |
> > Just as a proof-of-concept, here's one implementation of such a |
5 |
> > function, allowing for an arbitrary number of arguments: |
6 |
> > |
7 |
> > use_echo() { |
8 |
> > while [[ $# -gt 1 ]]; do |
9 |
> > if use "$1"; then |
10 |
> > echo "$2" |
11 |
> > return |
12 |
> > fi |
13 |
> > shift 2 |
14 |
> > done |
15 |
> > [[ $# -eq 1 ]] && echo "$1" |
16 |
> > } |
17 |
> |
18 |
> Looks good to me. If it doesn't get included in any eclass, I will just |
19 |
> paste it to the chromium ebuilds. :) |
20 |
> |
21 |
> Paweł |
22 |
> |
23 |
> I don't count but sometimes I do still read ebuilds, the function proposed |
24 |
look a bit^W unreadable to me, |
25 |
may I suggest to aggregate use and echo, separating them with a comma ",". |
26 |
The first element with an empty "use" always echo and return. |
27 |
|
28 |
See implementation and example below |
29 |
|
30 |
use_case() { |
31 |
local u |
32 |
local c |
33 |
while [[ $# -gt 0 ]] |
34 |
do |
35 |
u=${1%%,*} |
36 |
c=${1#*,} |
37 |
if [[ ${u} == "" ]] || use $u |
38 |
then |
39 |
echo ${c} |
40 |
break |
41 |
fi |
42 |
shift |
43 |
done |
44 |
} |
45 |
|
46 |
echo $(use_case useA,echoA useB,echoB ,echoC) |