This is the mail archive of the
mailing list for the Cygwin project.
bash and the current locale implementation
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin-developers at cygwin dot com
- Date: Thu, 1 Oct 2009 12:28:22 +0200
- Subject: bash and the current locale implementation
- Reply-to: cygwin-developers at cygwin dot com
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
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
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com