Marijn Schouten (hkBst) wrote:
> the current interface to use flags, useq, usev, use_with, use_enable, as
> defined in /usr/lib/portage/bin/ebuild.sh lacks generality. The common
> thing is testing a use flag and possibly echoing a string, but there is no
> function that implements this common behaviour.
> 
> I propose that we add such a function. Proposed name for the function is
> "ifuse".
>
I like the overall API that is enabled (and that it doesn't break anything.)

> I also propose to add the utility function "ifv" which is useful for
> writing concise and clean code.
>
This one seems a bit light-weight to me, but if it makes your life easier,
why not?

One minor thing; -n is the default test, so:
[[ $1 ]] is the same as [[ -n $1 ]]
and:
[[ ! $1 ]] is the same as [[ -z $1 ]]
''help test'' is very revealing, for those who haven't read it. ;-)

Also, you need to add quotes to the echo'ed vars, as Mr Marples outlined:

ifv() {
    [[ $1 ]] && echo "$2" || echo "$3"
}

If you don't, the vars will be split according to IFS, and treated as
separate parameters, eg:
~ $ a=$'blah\nfoo'
~ $ echo "$a"
blah
foo
~ $ echo $a
blah foo

The following sums up the whole quoting issue IMO:
"At its base, a shell is simply a macro processor that executes commands.
The term macro processor means functionality where text and symbols are
expanded to create larger expressions."
http://tiswww.tis.case.edu/~chet/bash/bashref.html


-- 
[EMAIL PROTECTED] mailing list

Reply via email to