Dnia 2013-08-03, o godz. 15:37:54 Alex Xu napisał(a): > On 03/08/13 02:29 PM, Michał Górny wrote: > > Dnia 2013-08-03, o godz. 17:54:42 > > Ulrich Mueller napisał(a): > > > >>>>>>> On Sat, 3 Aug 2013, Michał Górny wrote: > >> > >>> 2. The eclass comes with a pure bash-3.2 CamelCase converter for > >>> changing PNs like 'twisted-foo' into 'TwistedFoo'. The relevant code > >>> can be moved to eutils as portable replacements for bash-4 ${foo^} > >>> and friends. > >> > >>> # obtain octal ASCII code for the first letter. > >>> local ord=$(printf '%o' "'${fl}") > >>> > >>> # check if it's [a-z]. ASCII codes are locale-safe. > >>> if [[ ${ord} -ge 141 && ${ord} -le 172 ]]; then > >>> # now substract 040 to make it upper-case. > >>> # fun fact: in range 0141..0172, decimal '- 40' is fine. > >>> local ord=$(( ${ord} - 40)) > >>> # and convert it back to the character. > >>> fl=$(printf '\'${ord}) > >>> fi > >> > >> This looks just horrible. You do decimal arithmetic on octal numbers? > > > > Yes. Bash wasn't really happy to do octal arithmetic for me. Yet > > in this particular case, with proper assumptions, decimal arithmetic is > > practically equivalent. > > > > # obtain decimal ASCII code for the first letter. > local fl=$(printf '%d' "'${w}") > > # check if it's [a-z]. ASCII codes are locale-safe. > if [[ ${ord} -ge 97 && ${ord} -le 122 ]]; then > local ord=$(( ${ord} - 32 )) > # and convert it back to the character. > fl=$(printf '\'${ord}) > fi > > echo -n "${fl}${w:1}" > > Probably var names should be adjusted, I'm not too familiar with bash > locals. > > printf '%d' "'twisted" outputs "116" as expected, similar to > printf("%d", *"asdf qwerty") in C. > > Tested in Bash 4.2.45. You could test the whole snippet, not just the beginning. Then you would know that you're passing decimal to '\ooo' which expects octal. -- Best regards, Michał Górny