Le 03/12/2025 à 11:55, Oğuz écrivait :
On Wednesday, December 3, 2025, Léa Gris <[email protected] <mailto:[email protected]>> wrote:

    TMOUT=$(bc -l <<<'4*a(1)') bash -c 'read -rp "TMOUT=$TMOUT: ";
    printf "TMOUT=%f\\n" "$TMOUT"'
    TMOUT=3.14159265358979323844: bash: ligne 1 : printf:
    3.14159265358979323844: nombre non valable
    TMOUT=3,000000


Most command line tools outright ignore the user locale these days. I'm happy with what bash gets right and don't mind the rest

Ok then why does Bash parses the string value into float for the TMOUT variable as if LC_NUMERIC=C but not the string value into float for printf?

A language's grammar shall not be locale dependant. Parsing of the TMOUT string is correct. It is consistent regardless of the locale. bc, awk all are correct by using a decimal point and so having a consistently parseable interface that is not dependant on locale.

Bash parsing of the TMOUT variable using a decimal point is proof that Bash already has support for parsing string to float with a consistent grammar of decimal point.

--
Léa Gris

Reply via email to