René 'Necoro' Neumann wrote:
> cmake-utils_src_enable python => -DENABLE_python=...
> 
> Wanted would be that it returned -DENABLE_PYTHON=...
> 
> I'm not into bash scripting that much, so I do not know a way to do so -
> but I guess someone else is ;)
> 
Unfortunately BASH doesn't support ksh93 or zsh style casting to uppercase.
The best way really is via tr:
alias toUpper='tr [[:lower:]] [[:upper:]]'
alias toLower='tr [[:upper:]] [[:lower:]]'

(er aliases don't normally work in scripts, but you get the idea.) Bear in
mind that tr reads stdin and writes to stdout. It has the advantage of
being locale-safe. Every other method I've looked at is much slower and
only works with ASCII.

A function wouldn't be too hard:
toUpper() {
        for i; do
        echo "$i" |tr [[:lower:]] [[:upper:]]
        done
}

Usage depends on the parameters you pass.
var=$(toUpper $var) # for single vars with no newlines in
for i in $(toUpper "$@"); do # for multiple, if just simple flags with no
space, tabs or newlines.

IFS=$'\n'; before the above would deal with anything but newlines in the
vars. (We can get more complex but I doubt it's needed in this scope, much
as I hate leaving script in a technically unsafe state. If you're parsing
filenames, this is *not* safe.)

$ a='blah blah'
$ a=$(toUpper "$a")
$ echo "$a"
BLAH BLAH


-- 
[EMAIL PROTECTED] mailing list

Reply via email to