bug-bash
[Top][All Lists]
Advanced

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

Re: Subject: inaccurate character class processing


From: Greg Wooledge
Subject: Re: Subject: inaccurate character class processing
Date: Tue, 8 Jun 2010 10:22:17 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Jun 08, 2010 at 04:48:08PM +0300, Iosif Fettich wrote:
>         ls [A-Z]*
> 
>         doesn't work as expected/documented.
>         I'd want/expect it to list the filenames starting with an uppercase 
>         letter.

The results of this are dependent upon your locale.  If your locale is
set to C or POSIX, you will get what you expect.  If your locale is set
to something else (such as en_US.utf8) then you will get something
completely different.

I explain why this happens, on <http://mywiki.wooledge.org/locale>.

The glob in your command is expanded by bash (not ls), so in order to
get the results you want, your locale variables would have to be set to
C/POSIX *before* expanding the glob.  In other words, "LANG=C ls [A-Z]*"
will not work, since that sets the variable after expanding the glob.

This would work, although it's extremely awkward (IMHO):

  LANG=C bash -c 'ls [A-Z]*'

Another approach would be to permanently (or semi-permanently, e.g. just
for one shell session) set the LC_COLLATE variable.  Thus,

  export LC_COLLATE=C
  ls [A-Z]*

This will cause the ordering of glob results (and also of results generated
by ls itself, for example "ls" with no arguments, or "ls dirname") to be
in ASCII order, without throwing away the other locale features.



reply via email to

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