bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Surprising behavior with inline environment variable expansion


From: Chet Ramey
Subject: Re: Surprising behavior with inline environment variable expansion
Date: Wed, 26 Mar 2025 16:18:45 -0400
User-agent: Mozilla Thunderbird

On 3/26/25 6:52 AM, Léa Gris wrote:

LANG=C LC_NUMERIC=C printf '%s\t%f\t%f\n' "$LC_NUMERIC" 3.141592654 3,141592654

Outputs:

bash: printf: 3,141592654: invalid number
fr_FR.UTF-8    3.141593    3.000000

In this particular case, the expansion of LC_NUMERIC is performed before
the `printf' builtin is invoked, and the assignments preceding the
command don't affect it. (Variable assignments are processed after word
expansion.)

Even though LC_NUMERIC=C is used to correctly parse 3.141592654, the expansion of $LC_NUMERIC still prints its original value (fr_FR.UTF-8).

I think you're misunderstanding the order of execution here.

This may not necessarily be a bug, but the behavior is counterintuitive and inconsistent, making it difficult to predict how inline environment variables will affect both variable expansion and command execution. Some clarification in the Bash documentation could be helpful.

What additions would you suggest? The order of execution is described in
SIMPLE COMMAND EXPANSION. The locale variables and their precedence
hierarchy are described in Shell Variables with the rest of the variables
bash uses.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]