On Sun, 20 May 2007 10:41:09 +1000
Herbert Xu <[EMAIL PROTECTED]> wrote:

> On Sat, May 19, 2007 at 02:24:41PM +0200, Kevin F. Quinn wrote:
> > 
> > Step 1 says that variable assignment words are saved for processing
> > in steps 3 & 4, and step 2 performs expansion (including parameter
> > expansion), excluding variable assignments.  So in:
> > 
> >   x=${K:=dvb0.net0} A=${K#dvb} echo $A
> 
> Sorry, my mistake. I wanted say
> 
>       bash -c 'x=${K:=dvb0.net0} A=${K#dvb}' env | grep ^A=
> 
> but that actually works.  However, it is interesting to note that
> 
>       bash -c 'K=dvb0.net0 A=${K#dvb}' env | grep ^A=
> 
> produces
> 
>       A=

(I think you meant:

        bash -c 'x=${K:=dvb0.net0} A=${K#dvb} env' | grep ^A=
        bash -c 'K=dvb0.net0 A=${K#dvb} env' | grep ^A=
)

Although that second fails when written like that (bash 3.2.15(1)), it
does work interactively and in a script, so that's a bug in the bash
command line processing, I'd guess.

----
#!/bin/bash
unset A K
K=dvb0.net0 A=${K#dvb} eval echo \$A
unset A K
x=${K:=dvb0.net0} A=${K#dvb} echo $A
unset A K
K=dvb0.net0 A=${K#dvb} env | grep ^A=
unset A K
x=${K:=dvb0.net0} A=${K#dvb} env | grep ^A=
----

yields:

----
0.net0

A=0.net0
A=0.net0
----

With dash it yields 

----


A=
A=0.net0
----

> So I still stand by my statement that script writers on Linux cannot
> safely rely on this construct.
> 
> As it is, we have two different behaviours, one given by the Korn
> shell and another shared by most BSD-derived Bourne shells.  I have
> not seen any convincing evidence that either is not compliant with
> respect to POSIX.

I still think the standard is pretty clear.  However if BSD sh has never
worked like that, I don't see how the standard ended up the way it did,
given it was written to document what could be relied on across
existing Unix variants at the time.

> The behaviour of bash is closer to that of the Korn shell but is
> different enough that this construct cannot be reliably used.
> 
> Cheers,


-- 
Kevin F. Quinn

Attachment: signature.asc
Description: PGP signature

Reply via email to