bash and the current locale implementation

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Oct 1 10:28:00 GMT 2009


Hi guys,


We have a problem with bash.

I'm using tcsh as my default shell, so I didn't see this problem
earlier.  When you enter `setenv LANG=foo' in tcsh, it changes its its
own environment and calls setlocale (LC_ALL, "").  Everything's fine.

Bash, OTOH, does not do anything of this.  Assuming you enter `export
LANG=foo', bash will not at all change its own environment.  No call to
setenv, or putenv, or even a replacement of the environ pointer.
Rather, the environment change will only be visible to subsequent child
processes.

Consequentially, bash can't just call setlocale (LC_ALL, "").  Instead,
bash calls the following:

  setlocale (LC_CTYPE, "foo");
  setlocale (LC_NUMERIC, "foo");
  setlocale (LC_TIME, "foo");
  [...]

Even if the own environment would have been changed by bash, none of
these calls will trigger a change of the charset used by Cygwin
internally.  The trigger is the empty locale string "" since that what
Cygwin uses internally and that's what applications usually do to get
the locale setting from the environment.  The trigger problem isn't
that much of a problem, of course, the missing environment change is. 

So, here's bash.  No environment change, and conseqentially no standard
setlocale call.  The result is that the charset used by Cygwin is not
what the user expected when setting LANG (or LC_ALL, or LC_CTYPE) in the
environment in this instance of bash.  That's especially visible in the
console.  The console will still use UTF-8, while bash expects, for
instance, CP1252.  Pressing the a-umlaut key on a german keyboard will
have a funny result.  Only when starting a child bash from here will
correct this problem.

Same goes for dash, btw, but it isn't locale-aware anyway.

Does anybody have a nifty, easy to implement idea how to workaround this
problem in bash?  It's a bit unfortunate that bash only switches to the
correct charset if the setting is made in Cygwin.bat or in the parent
process, IMHO.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-developers mailing list