[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
environment variable assignments are ignored by printf built-in
From: |
Bruno Haible |
Subject: |
environment variable assignments are ignored by printf built-in |
Date: |
Sun, 28 Nov 2010 01:47:23 +0100 |
User-agent: |
KMail/1.9.9 |
Hi,
An assignment to the LANG variable appears to have no effect when
executed in the same 'simple command' as the 'printf' built-in.
How to reproduce:
- Use bash-4.1 or bash-3.2.39.
- On a system with a German (or French) locale installed.
$ unset LC_ALL LC_NUMERIC
$ export LANG=de_DE.UTF-8
$ printf '%.4f\n' 1
1,0000 # correct
$ LANG=C printf '%.4f\n' 1
1,0000 # should be 1.0000
$ LANG=C /usr/bin/printf '%.4f\n' 1
1.0000 # correct
$ env LANG=C printf '%.4f\n' 1
1.0000 # correct
$ (LANG=C; printf '%.4f\n' 1)
1.0000 # correct
Similarly for LC_ALL instead of LANG.
Rationale:
POSIX:2008 description of the execution of simple commands. Section 2.9.1 in
<http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html>.
"A "simple command" is a sequence of optional variable assignments
and redirections, in any sequence, optionally followed by words and
redirections, terminated by a control operator.
... the following expansions, assignments, and redirections shall all
be performed from the beginning of the command text to the end:
1. The words that are recognized as variable assignments or
redirections according to Shell Grammar Rules are saved for
processing in steps 3 and 4.
...
4. Each variable assignment shall be expanded for tilde expansion,
parameter expansion, command substitution, arithmetic expansion,
and quote removal prior to assigning the value.
...
If no command name results, variable assignments shall affect the current
execution environment. Otherwise, the variable assignments shall be
exported for the execution environment of the command and shall not affect
the current execution environment (except for special built-ins)."
So, in the simple command "LANG=C printf '%.4f\n' 1" the LANG=C assignment
should be effective for the execution of the printf command. Regardless
whether it is built-in or not, because the cited text does not make a
distinction between built-ins and other commands.
Bruno
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- environment variable assignments are ignored by printf built-in,
Bruno Haible <=