I like to disable all locale specific differences in shell scripts. What is the preferred way to do it?
LANG=C or LC_ALL=C
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
LANG sets the default locale, i.e. the locale used when no more specific setting (LC_COLLATE, LC_NUMERIC, LC_TIME etc.) is provided; it doesn’t override any setting, it provides the base value. LC_ALL on the other hand overrides all locale settings.
Thus to override scripts’ settings, you should set LC_ALL.
You can check the effects of your settings by running locale. It shows the calculated values, in quotes, for all locale categories which aren’t explicitly set; in your example, LANG isn’t overriding LC_NUMERIC, it’s providing the default value. If LC_ALL and LC_NUMERIC aren’t set in the environment, the locale is taken from LANG, and locale shows that value for LC_NUMERIC, as indicated by the quotes.
See the locales manpage and the POSIX definitions of environment variables for details. See also How does the “locale” program work?
Method 2
LANG does not override:
$ export LC_NUMERIC="de_DE.UTF-8" $ export LANG=C $ printf "%.2fn" 3.14 -bash: printf: 3.14: invalid number 3,00
But LC_ALL does:
$ export LC_NUMERIC="de_DE.UTF-8" $ export LC_ALL=C $ printf "%.2fn" 3.14 3.14
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0