[Gllug] Bash character-range and locale

Richard Huxton dev at archonet.com
Wed Mar 7 09:35:48 UTC 2007


Just something I noticed for the first time today. I don't do a lot in 
shell, but had a "find" trick me this morning.

$ ls; ls h*; ls [h]*; ls [h-h]*
hello  Hello
hello
hello
hello

So far, so good...

$ ls [g-i]*
hello  Hello

Ah, that'll be locale settings. I'm running en_GB.UTF-8, so my alphabet 
must be sorting aAbBcCdD...

$ LC_COLLATE=C
$ ls [g-i]*
hello
$ export LC_COLLATE=
$ ls [g-i]*
hello  Hello

Yep, that's it. However...

$ LC_COLLATE=C ls [g-i]*
Hello  hello

Fair enough - I'm guessing it's because bash is expanding the 
character-set whereas the variable-setting only applies to the "ls".

I take it that if I want to override locale for one command, I'll need 
something like:
$ LC_COLLATE=C bash -c 'ls [g-i]*'
hello

Hmm - makes sense, but irritating. Need some dwimmery that notices 
whether I'm acting as a user (locale=en_gb) or developer (locale=C).

-- 
   Richard Huxton
   Archonet Ltd
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list