LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Forcing utility output in specific locale (LANG=en_US.UTF-8) (https://www.linuxquestions.org/questions/linux-newbie-8/forcing-utility-output-in-specific-locale-lang%3Den_us-utf-8-a-923549/)

davidlt 01-13-2012 01:25 AM

Forcing utility output in specific locale (LANG=en_US.UTF-8)
 
I am running my scripts on machines with different locales and at least who produces different dates depending on the locale.

Code:

$ ssh davidlt@machine 'who -s'
davidlt  pts/0        Jan 12 16:54 (empty.lt)

$ who -s
david    console  Jan 13 07:08

$ env -i LANG=en_US.UTF-8 ssh davidlt@lxbuild170 'who -s'
davidlt  pts/0        2012-01-12 16:54 (empty.lt)

$ ssh davidlt@machine 'who -s'
davidlt  pts/0        Jan 12 16:54 (empty.lt)

In the first example SSH send LANG and LC_* variables to the remote machine. So, lt_LT.UTF-8 was set. In the second example the same locale was used on my local machine. On the third example I have tried running a clean environment, which does not have any LANG or LC_* set and setting it myself. Now I got the date I wanted.

Code:

$ LANG=en_US.UTF-8 who -s
david    console  Jan 13 07:08

$ LANG=en_US.UTF-8 bash -c 'who -s'
david    console  Jan 13 07:08

$ LANG=en_US.UTF-8 bash -c 'env' | grep LANG
LANG=en_US.UTF-8

$ env -i LANG=lt_LT.UTF-8 ssh davidlt@lxbuild170 'who -s'
davidlt  pts/0        2012-01-12 16:54 (empty.lt)

Well, after playing more I can see that changing LANG, which also modifies all LC_* does not give any result. Even if variable is set, the default locale is used (lt_LT.UTF-8). The last example illustrates that very well.

It looks like env does the magic forcing command to run in the different locale, but only en_US.UTF-8? But it doesn't work on the local machine commands.

How do I force command to use en_US.UTF-8 locale?

Thanks!
David

Jim4Prez 01-17-2012 05:59 AM

Instead of passing LANG to the invocation of ssh, pass it as part of the command that you want ssh to run.

pluto@work$ LANG=lt_LT.UTF-8 ssh home 'env'
_=/usr/bin/env
HOME=/home/pluto
LANG=en_US.UTF-8
LOGNAME=pluto
...

pluto@work$ ssh work 'LANG=lt_LT.UTF-8 env'
_=/usr/bin/env
HOME=/home/pluto
LANG=lt_LT.UTF-8
LOGNAME=pluto
...


All times are GMT -5. The time now is 08:50 AM.