Command line arguments depend on locale

Pádraig Brady P at draigBrady.com
Thu Jan 31 18:25:48 UTC 2013


On 01/30/2013 11:05 PM, Benny Amorsen wrote:
> Apparently ping has now started interpreting its command line arguments
> depending on locale. I.e. ping -i 0.1 no longer works in locales where
> comma is the decimal separator.
>
> This makes it difficult to call system commands. The only workaround is
> to set LC_ALL to a known-good locale, but then your users get no benefit
> from the translations of error messages and so on.
>
> Is Linux really doomed to repeat the mistakes made by Visual Basic more
> than a decade ago?

Yes this is a slippery slope.
ping is definitely wrong to do this IMHO.

A less clear cut example is printf(1).
POSIX states that LC_NUMERIC controls the format
of the numbers _written_.
In coreutils we're careful to reset to the C locale
so that strtod etc. work consistently.

Just testing bash here shows it was a different interpretation
which I would deem not what POSIX intended:

# coreutils
$ LC_NUMERIC=de_DE env printf "%f\n" 0.1
0,100000
$ LC_NUMERIC=de_DE env printf "%f\n" 0,1
printf: 0,1: value not completely converted
0,000000

# bash
$ LC_NUMERIC=de_DE printf "%f\n" 0,1
0,100000
$ LC_NUMERIC=de_DE printf "%f\n" 0.1
bash: printf: 0.1: invalid number
0,000000

cheers,
Pádraig


More information about the devel mailing list