tech-userlevel archive

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

Re: bin/47597: local and $() don't play well with each other



On Tue, Feb 26, 2013 at 02:33:51PM +0100, Steffen Daode Nurpmeso wrote:
> 
>  |The question was whether I could rely upon NetBSD's sh not being "fixed"
>  |to act like the (absurd) ksh/SUS does?
> 
> My personal feeling is however also that the standard is absurd in
> that it requires that VAR of 'VAR=VAL util' is treated as an
> assigned if 'util' is a special shell builtin utility, but not
> otherwise (because who can write stable scripts like that?).

No: the standard just says that the assignment remains in effect after
the builtin has completed if it is a special-builtin, but shall not
remain if it is not. The assignment in the not special-builtin is
"local", or just in the scope of the not special-builtin function.

The problem is not that the assignement is not made.

Furthermore, there is the problem of the parsing of the command. If the
assignment is made this way:

$ foo=bar
$ foo=XXX echo $foo

the substitutions are made before the command is executed, hence:

foo=XXX echo bar

is executed. While if the echo $foo is made in a function:

foo=XXX f

is subject to substitutions leading to:

foo=XXX f

(unchanged) and this works.
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                      http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index