1 |
René 'Necoro' Neumann wrote: |
2 |
> cmake-utils_src_enable python => -DENABLE_python=... |
3 |
> |
4 |
> Wanted would be that it returned -DENABLE_PYTHON=... |
5 |
> |
6 |
> I'm not into bash scripting that much, so I do not know a way to do so - |
7 |
> but I guess someone else is ;) |
8 |
> |
9 |
Unfortunately BASH doesn't support ksh93 or zsh style casting to uppercase. |
10 |
The best way really is via tr: |
11 |
alias toUpper='tr [[:lower:]] [[:upper:]]' |
12 |
alias toLower='tr [[:upper:]] [[:lower:]]' |
13 |
|
14 |
(er aliases don't normally work in scripts, but you get the idea.) Bear in |
15 |
mind that tr reads stdin and writes to stdout. It has the advantage of |
16 |
being locale-safe. Every other method I've looked at is much slower and |
17 |
only works with ASCII. |
18 |
|
19 |
A function wouldn't be too hard: |
20 |
toUpper() { |
21 |
for i; do |
22 |
echo "$i" |tr [[:lower:]] [[:upper:]] |
23 |
done |
24 |
} |
25 |
|
26 |
Usage depends on the parameters you pass. |
27 |
var=$(toUpper $var) # for single vars with no newlines in |
28 |
for i in $(toUpper "$@"); do # for multiple, if just simple flags with no |
29 |
space, tabs or newlines. |
30 |
|
31 |
IFS=$'\n'; before the above would deal with anything but newlines in the |
32 |
vars. (We can get more complex but I doubt it's needed in this scope, much |
33 |
as I hate leaving script in a technically unsafe state. If you're parsing |
34 |
filenames, this is *not* safe.) |
35 |
|
36 |
$ a='blah blah' |
37 |
$ a=$(toUpper "$a") |
38 |
$ echo "$a" |
39 |
BLAH BLAH |
40 |
|
41 |
|
42 |
-- |
43 |
gentoo-dev@g.o mailing list |