5

Using a seq command with floating point numbers, my output comes with commas instead of dots as decimal separators, despite using dots in the input:

seq 0.1 0.3 1.3
0,1
0,4
0,7
1,0
1,3

I assumed this to be linked with the locale LC_NUMERIC, which is set to de_DE.UTF-8, however a change to en_US.UTF-8 did not fix it and another system I have using the very same locale settings does return dots. Even explicitly defining a format via e.g. -f %1.2 does not return dots but commas as decimal separators.

Where and how do I change this behaviour? How to ensure my script will error-free on any given system? Obviously any output will be unusable for further processing if not reprocessed via tr the like.

Using an English installation of Mint in German time zone and raspian on the other machine.


Edit: locale settings on the given machines:

The "comma" one:

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

The "dot" one:

LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="C.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

Setting LANGUAGE does not affect the result.

  • The answer at StackOverflow does not seem to help and when sshing into either machine the behaviour is as the server defines. – Fiximan Feb 1 at 22:08
3

To exclude errors in the locales themselves, I (re)generated both de_DE.UTF-8 and en_US.UTF-8 via

dpkg-reconfigure locales

and now seq behaviour seems to be dependent on LC_NUMERIC AND LANG.

If LC_NUMERIC is unset/empty, LANG defines the bahaviour otherwise toggling LC_NUMERIC betweende_DE.UTF-8 and en_US.UTF-8 switches between commas and dots, respectively.


Specific dangers

In the very case of setting a wrong/inexistent value for LANG and a non-dot-based locale, behaviour might be mixed in some special cases, e.g.

LANG=en_US
#it should be en_US.UTF-8
LC_NUMERIC=de_DE.UTF-8

seq 0.1 0.2 1.3
0.1
0.3
0.5
0.7
0.9
1.1
1,3

It does not appear for seq 0.1 0.2 1.4 but also for seq 0.1 0.2 1.9 - very odd and IMHO very dangerous behaviour. So be careful with the portability of seq or define locales for any script.

Wildly guessing, this seems to be related to some manual change in specific cases (see: https://lists.gnu.org/archive/html/bug-coreutils/2008-09/msg00192.html)


UPDATE:

The maintainers' suggestion to avoid any errors due to localized output formats is to define the locale in the script itself ( LC_NUMERIC=C ). Changing this behaviour is not planned. (See linked thread with patch below)

The problem with mixed dot and comma output due to bad locale settings has been recognised as a bug and already patched by the maintainers:

https://lists.gnu.org/archive/html/coreutils/2019-02/msg00002.html

  • 2
    Die you Report a bug for it? – eckes Feb 2 at 18:00
  • 2
    @eckes Yes, patch already available, see updated answer. – Fiximan Feb 3 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.