bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [A-Z], [:upper:]


From: Eric Blake
Subject: Re: [A-Z], [:upper:]
Date: Thu, 28 Mar 2019 16:24:03 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.0

On 3/28/19 3:30 PM, Norman H. Azadian wrote:

> Description:
>         In version 4 [A-Z] is broken and [:upper:] works.

Depends on your definition of broken and works. In version 4, ranges are
locale dependent; if you are using LC_ALL=C, then it is 26 letters, if
you are using any other locale, then it might include other letters
depending on what your locale things should belong in that range (some
locales have been known to add a-y or b-z, depending on whether the
locale sorts words case-insensitively but also on whether it lists aA or
Aa in its collation tables).  [:upper:] is a glob that matches exactly 5
possible characters: ':', 'u', 'p', 'e', or 'r'.  Maybe you meant
[[:upper:]], which instead a glob that matches all characters that your
current locale treats as isupper()?

>     In version 5, the situation is reversed.

In bash 5, Chet provided the option for the build to default to Rational
Range Interpretation (you can still choose at build time whether to flip
that on or off by default, if I recall correctly, but I like it flipped
on). When enabled, [A-Z] is a glob that matches exactly 26 letters,
regardless of your locale.  If RRI is enabled, that explains why [A-Z]
does what you wanted.

Meanwhile, depending on your version of libc, your locale's definitions
may be different (there has been work at getting glibc locales to behave
more like RRI in ALL locales, just because so many people are confused
by the locale-specific nature of ranges otherwise).

> 
> Repeat-By:
>     foo=ABC ; echo ${foo%[A-Z]} ${foo%[:upper:]}

If you want [[:upper:]] to work, you have to spell it correctly.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]