SDB:Changes in Posix.2
Version: 9.1
İçindekiler
Symptom
You use a shell script or a command for editing classifications ([A-Z]), making calculations with numbers with a decimal separator (1.5), or sorting. However, the results produced recently by this command or script differ from previous ones.
Examples
Sorting:
user@earth:~> export LC_COLLATE=de_DE user@earth:~> ls aaa AAA bbb BBB ccc CCC user@earth:~> export LC_COLLATE=sk_SK user@earth:~> ls AAA aaa BBB bbb CCC ccc
Ranges:
user@earth:~> export LC_COLLATE=de_DE user@earth:~> echo [a-c]* aaa AAA bbb BBB ccc user@earth:~> export LC_COLLATE=sk_SK user@earth:~> echo [a-c]* aaa BBB bbb CCC ccc
Calculations with decimal separators:
user@earth:~> LC_NUMERIC=de_DE user@earth:~> awk 'BEGIN{x=0} {x+=$1} END{print x}' <<END > 1.5 > 2 > END 3 user@earth:~> LC_NUMERIC=en_US user@earth:~> awk 'BEGIN{x=0} {x+=$1} END{print x}' <<END > 1.5 > 2 > END 3.5
Cause
Many programs, including Bash, take language-specific differences into account when sorting or calculating. For example, sorting operations in German are case-insensitive, but in Slovak, uppercase always precedes lowercase letters.
Solution
If you expect certain tasks and build subsequent script components on these expectations, make sure that the script runs in a defined environment, that is, the language (locale) must be set. This can be easily done by way of the variable LC_ALL
. For this purpose, insert export LC_ALL=C
at the beginning of the script to ensure that the output suits your needs.
<keyword>bash,LANG,locale,posix,ranges,calc,float,number,format</keyword>