1 |
On 13:34 Fri 05 Oct , Steve Long wrote: |
2 |
> Roy Marples wrote: |
3 |
> > IFS=- |
4 |
> > set -- ${CHOST} |
5 |
> > spec=$2 |
6 |
> > |
7 |
> > Works fine in bash - and other shells. |
8 |
> > |
9 |
> Yeah fine, there are kludgy workarounds; so what? Doesn't mean I want to use |
10 |
> them. ;) |
11 |
> In actual fact, I'd be more likely to use parameter expansion than set, eg: |
12 |
> spec=${CHOST#*-*-} # chop first two fields off so spec is fields 3 on |
13 |
> spec=${spec%%-*} # chop all but first off so left with just field 3 |
14 |
> ..which I believe works in sh[1] as well. The point for me, however, is not |
15 |
> whether sh can be kludged to do something, it's what the most efficient |
16 |
> ways to do something in scripts are. Whether you use pe, read or an array, |
17 |
> avoiding externals leads to quicker scripts.[2] |
18 |
|
19 |
That parameter workaround wouldn't work, because CHOST may also contain |
20 |
just 3 fields, as it does on Gentoo/BSD. Unpack a portage tarball and |
21 |
look at the make.conf's if you're curious. |
22 |
|
23 |
Avoiding externals at the cost of added complexity on something that |
24 |
only gets called one time certainly qualifies as premature optimization. |
25 |
|
26 |
Thanks, |
27 |
Donnie |
28 |
-- |
29 |
gentoo-dev@g.o mailing list |