LANG=C is in a number of the /etc/init.d/* scripts. What does LANG=C do and why do you need to set LANG=C.

16,958

Solution 1

It forces applications to use the default language for output, and forces sorting to be bytewise.

$ LANG=es_ES man
¿Qué página de manual desea?
$ LANG=C man
What manual page do you want?
$ LANG=en_US sort <<< $'a\nb\nA\nB'
a
A
b
B
$ LANG=C sort <<< $'a\nb\nA\nB'
A
B
a
b

Solution 2

As already explained, the LANG environment variable controls localization.

It affects many standard command-line tools like sort, grep, awk.

Setting its value to "C" tells all those tools to consider only basic ASCII characters and disable UTF-8 multibyte match.

Another good reason than localisation to use that environment variable is performance: it can make grep 1000 times faster for grep versions < 2.7 : http://rg03.wordpress.com/2009/09/09/gnu-grep-is-slow-on-utf-8/

On the reason why the letter "C" is used to specify a "safe" basic locale, see Why "LANG=C"? (not D or E or F).

Solution 3

LANG=C is a way to disable localization. It's used in scripts to predict program output which may vary based on current language. For more information read this

Share:
16,958

Related videos on Youtube

nelaaro
Author by

nelaaro

Linux admin, tech enthusiast. opensource evangelist.

Updated on September 18, 2022

Comments

  • nelaaro
    nelaaro over 1 year

    Its not clear what it does or what it contains. I tried greping the out put of set and env to see what C or LANG are set to in other places on the systems. Nothing was clear about how it is used or set. I don't even know what man page I should even start reading.

    Any help here would be great as I try to decode the start up scripts on different Linux machines. If any one can recommend a good resources (books,documentation) that would help along this process That would be much appreciated.

    Example of scripts using LANG=C on a centos6 machine

    $ grep -i LANG=C ./*
    ./halt:LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/dev/{next}
    ./netconsole:   route=$(LANG=C ip -o route get to $host/32)
    ./netconsole:           arp=$(LANG=C /sbin/arping -c 1 -I $DEV $target 2>/dev/null | awk '/ reply from .*[.*]/ { print gensub(".* reply from .* \\[(.*)\\].*","\\1","G") }')
    ./netconsole:                   SYSLOGADDR=$(LANG=C host $SYSLOGADDR 2>/dev/null | awk '/has address / { print $NF }')
    ./network:          LANG=C sed -e "$__sed_discard_ignored_files" \
    ./network:          LANG=C sort -k 1,1 -k 2n | \
    ./network:          LANG=C sed 's/ //')
    ./network:              eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
    ./network:              eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
    ./network:              eval $(LANG=C fgrep "SLAVE=" ifcfg-$i)
    ./network:              if LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i > /dev/null ; then
    ./network:            if ! LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i >/dev/null 2>&1 ; then
    ./network:              eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
    ./network:              eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
    ./rpcbind:# We can't Japanese on normal console at boot time, so force LANG=C.
    ./rpcbind:        LANG=C
    

    Example useage in scripts on a ubuntu 10.04 machine

    $ grep -i LANG=C ./*
    ./apache2:ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
    ./exim4:LANG=C
    ./ntop:export LANG=C\
    
    • Erik Bennett
      Erik Bennett about 5 years
      As a word of caution, changing LANG=C in your .bashrc (depending on your shell) will break some newer GUI console login behavior. It breaks CentOS 7.6, at least. (ask me how I know this)