1 |
Marijn Schouten (hkBst) wrote: |
2 |
> the current interface to use flags, useq, usev, use_with, use_enable, as |
3 |
> defined in /usr/lib/portage/bin/ebuild.sh lacks generality. The common |
4 |
> thing is testing a use flag and possibly echoing a string, but there is no |
5 |
> function that implements this common behaviour. |
6 |
> |
7 |
> I propose that we add such a function. Proposed name for the function is |
8 |
> "ifuse". |
9 |
> |
10 |
I like the overall API that is enabled (and that it doesn't break anything.) |
11 |
|
12 |
> I also propose to add the utility function "ifv" which is useful for |
13 |
> writing concise and clean code. |
14 |
> |
15 |
This one seems a bit light-weight to me, but if it makes your life easier, |
16 |
why not? |
17 |
|
18 |
One minor thing; -n is the default test, so: |
19 |
[[ $1 ]] is the same as [[ -n $1 ]] |
20 |
and: |
21 |
[[ ! $1 ]] is the same as [[ -z $1 ]] |
22 |
''help test'' is very revealing, for those who haven't read it. ;-) |
23 |
|
24 |
Also, you need to add quotes to the echo'ed vars, as Mr Marples outlined: |
25 |
|
26 |
ifv() { |
27 |
[[ $1 ]] && echo "$2" || echo "$3" |
28 |
} |
29 |
|
30 |
If you don't, the vars will be split according to IFS, and treated as |
31 |
separate parameters, eg: |
32 |
~ $ a=$'blah\nfoo' |
33 |
~ $ echo "$a" |
34 |
blah |
35 |
foo |
36 |
~ $ echo $a |
37 |
blah foo |
38 |
|
39 |
The following sums up the whole quoting issue IMO: |
40 |
"At its base, a shell is simply a macro processor that executes commands. |
41 |
The term macro processor means functionality where text and symbols are |
42 |
expanded to create larger expressions." |
43 |
http://tiswww.tis.case.edu/~chet/bash/bashref.html |
44 |
|
45 |
|
46 |
-- |
47 |
gentoo-dev@g.o mailing list |