Undestanding LANG setting in /etc/environment | Unix Linux Forums | AIX

  Go Back    


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

Undestanding LANG setting in /etc/environment

AIX


Tags
aix, unix

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-09-2013
Aaron Boyce Aaron Boyce is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 11 March 2013, 11:06 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Undestanding LANG setting in /etc/environment

Hi All,

We had issue with a application which reports process counts in log, application used to log process counts as Integer data type (1500).

One fine morning we started seeing process counts in application log as Decimal (1,500).

Our UNIX admin did investigate and figured-out that change in LANG setting in /etc/environment has caused application to log process counts in log as Decimal instead of Integer and was told that LANG was changed to en_US from C.

Here I am trying to understand why this should cause Integer values in log got changed to Decimal data type.

I would appreciate if anybody can help me to understand.

Thanks
Aaron
Sponsored Links
    #2  
Old 03-10-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 29 August 2014, 5:55 PM EDT
Location: Galactic Empire
Posts: 3,362
Thanks: 230
Thanked 1,197 Times in 1,125 Posts
Different countries & cultures often use different conventions to format numbers, to write the date and time or to delimit words and phrases.

C locale is a rather neutral locale which has same settings across different systems.

But in en_US locale, the number format changes and is represented with a thousand separator.

See below how gawk output changes when I specify different locales:

Code:
$ LC_ALL=C gawk 'BEGIN{printf "%'\''d\n", 1234}'
1234
$ LC_ALL=en_US gawk 'BEGIN{printf "%'\''d\n", 1234}'
1,234

I hope this helps.
Sponsored Links
    #3  
Old 03-10-2013
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 Posts
What happens if you change LANG back to C, assuming it was changed? Does that fix the problem? Is the timestamp consistent with the date of that fine morning when the problem started?

1500 and 1,500 both seem "integer" to me, so I don't understand why you say "decimal" to describe the problem. Aren't those two numbers the same, with the only difference whether a thousands separator is used?
    #4  
Old 03-10-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 30 August 2014, 7:45 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,204
Thanks: 44
Thanked 800 Times in 631 Posts
Quote:
Originally Posted by Aaron Boyce View Post
Our UNIX admin did investigate and figured-out that change in LANG setting in /etc/environment has caused application to log process counts in log as Decimal instead of Integer and was told that LANG was changed to en_US from C.
There are many AIX facilities which are represented differently in various cultures. Language (of the man pages, of command status output, ...), how numbers are represented, keyboard layout and many other things. All this is controlled by some environment variables of which "LANG" is one (and probably the most important). Issue the "set" command and you will see "LANG", but probably also "LC_MESSAGES" and a few others.

It is possible to control this "language environment" for every process separately, simply by setting the language variable to a different value upon process start, like this:


Code:
# (export LANG=<some_value> ; command)

Now for the role of "/etc/environment": as you have issued "set" you sure have noticed there are a lot of variables assigned. Most of these variables are not set explicitly by you, but get assigned default values. These system-wide default values are stored in "/etc/environment". Have a look at it, it is a simple text file with declarations in the form


Code:
# comment line
variable=value

Every time you log in your environment initially gets filled with these defaults. After this your own changes to the environment are being applied and you can change and override any of these defaults. You certainly have a special user for the program you are talking about. If you depend on the LANG variable to have a certain value it is a wise idea to explicitly set it in your startup scripts ("~/.profile") even if it is to the same value as the default. Even if the default changes your environment will remain as it is. I suggest to add a line


Code:
LANG=C ; export LANG

to your profile or shell startup script. The "export" keyword will make sure every process started from this process inherits this setting. Btw.: the same is true for other environment settings one of your programs depend on. Set these explicitly, even if it is to the same value the variable already has. When the default changes you avoid possible problems.

I hope this helps.

bakunin
Sponsored Links
    #5  
Old 03-10-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 August 2014, 5:38 AM EDT
Location: San Jose, CA, USA
Posts: 4,474
Thanks: 176
Thanked 1,502 Times in 1,274 Posts
Quote:
Originally Posted by bakunin View Post
There are many AIX facilities which are represented differently in various cultures. Language (of the man pages, of command status output, ...), how numbers are represented, keyboard layout and many other things. All this is controlled by some environment variables of which "LANG" is one (and probably the most important). Issue the "set" command and you will see "LANG", but probably also "LC_MESSAGES" and a few others.

It is possible to control this "language environment" for every process separately, simply by setting the language variable to a different value upon process start, like this:


Code:
# (export LANG=<some_value> ; command)

Now for the role of "/etc/environment": as you have issued "set" you sure have noticed there are a lot of variables assigned. Most of these variables are not set explicitly by you, but get assigned default values. These system-wide default values are stored in "/etc/environment". Have a look at it, it is a simple text file with declarations in the form


Code:
# comment line
variable=value

Every time you log in your environment initially gets filled with these defaults. After this your own changes to the environment are being applied and you can change and override any of these defaults. You certainly have a special user for the program you are talking about. If you depend on the LANG variable to have a certain value it is a wise idea to explicitly set it in your startup scripts ("~/.profile") even if it is to the same value as the default. Even if the default changes your environment will remain as it is. I suggest to add a line


Code:
LANG=C ; export LANG

to your profile or shell startup script. The "export" keyword will make sure every process started from this process inherits this setting. Btw.: the same is true for other environment settings one of your programs depend on. Set these explicitly, even if it is to the same value the variable already has. When the default changes you avoid possible problems.

I hope this helps.

bakunin
Setting LANG=C will do what Aaron Boyce wants only if neither LC_ALL nor LC_NUMERIC is set in the environment. LC_NUMERIC will override LANG for purposes of determining the radix character used and the formatting of numeric output. LC_ALL will override both LANG and LC_NUMERIC.

If LC_NUMERIC is effectively set to a value that sets non-null thousands separators or that uses comma as the radix character, you need to take extra precautions when working with CSV files that contain numeric strings that represent non-integral values, or integral values greater than 999 or less than -999.
Sponsored Links
    #6  
Old 03-10-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 30 August 2014, 7:45 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,204
Thanks: 44
Thanked 800 Times in 631 Posts
Quote:
Originally Posted by Don Cragun View Post
Setting LANG=C will do what Aaron Boyce wants only if neither LC_ALL nor LC_NUMERIC is set in the environment. LC_NUMERIC will override LANG for purposes of determining the radix character used and the formatting of numeric output. LC_ALL will override both LANG and LC_NUMERIC.

If LC_NUMERIC is effectively set to a value that sets non-null thousands separators or that uses comma as the radix character, you need to take extra precautions when working with CSV files that contain numeric strings that represent non-integral values, or integral values greater than 999 or less than -999.
You are right, Don, as always. In his entry posting Aaron stated that his SysAdmin has traced back the problem to the changed LANG-entry in /etc/environment , so i took it that none of the applicable LC_-variables are defined in his case, because these would have overridden the old as well as the new setting.

Still, its a good idea to explain the interdependence of LANG and LC_ALL the other LC_-variables.

I hope this helps.

bakunin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Setting Environment Variables bigubosu UNIX for Dummies Questions & Answers 4 04-30-2010 06:23 AM
Need help with setting up environment variables SSSB UNIX for Dummies Questions & Answers 1 01-21-2010 02:44 PM
Setting up your environment sa_ken UNIX for Dummies Questions & Answers 5 11-04-2009 09:08 AM
Problem setting environment... huskie69 Shell Programming and Scripting 2 09-01-2009 04:46 AM
Setting the $LANG info needed deedaz UNIX for Dummies Questions & Answers 2 01-27-2008 10:29 AM



All times are GMT -4. The time now is 10:15 AM.