Stephane Chazelas | 3 Jan 2012 22:34
Picon
Favicon

Re: Case modification

2011-12-24 15:48:42 -0500, Chet Ramey:
> On 12/23/11 7:02 PM, Bill Gradwohl wrote:
> 
> > Therefore, pattern (can not be / should not be) more than 1 character,
> > unless its within [ ] then each character gets its turn. Reading the man
> > page does not give me that impression. It hints at it, but is nebulous
> > enough to allow other interpretations.
> 
> Let's see how we can make the documentation clearer.  I think it takes only
> these two additional sentences in the description:
> 
> "Each character in the expanded value of  <at> var{parameter} is tested against
>  <at> var{pattern}, and, if it matches the pattern, its case is converted.
> The pattern should not attempt to match more than one character."
> 
> And, for what it's worth, the number of characters in a [...] pattern does
> not matter: a bracket expression can only ever match a single character.
[...]

What's the rational behind such a contrieved operator, BTW.

For comparison, in zsh, there are:

Using expansion flags:

~$ a='foo BAR'
~$ echo ${(U)a}  # upper
FOO BAR
~$ echo ${(L)a}  # lower
foo bar
~$ echo ${(C)a}  # capitalise
Foo Bar

Or if you do need to convert only some letters (but why would you?):
~$ echo ${a//(#m)[oa]/${(U)MATCH}}
fOO BAR

Or, a la csh/tcsh:

~$ echo $a:l
foo bar
~$ echo $a:u
FOO BAR

(those modifiers can also apply to history expansion and in globbing qualifiers)

--

-- 
Stephane


Gmane