bug-bash
[Top][All Lists]
Advanced

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

Re: Assigning to multiple variables on same line


From: Mike Frysinger
Subject: Re: Assigning to multiple variables on same line
Date: Thu, 13 Aug 2009 02:45:51 -0400
User-agent: KMail/1.11.4 (Linux/2.6.30.3; KDE/4.2.4; x86_64; ; )

On Monday 10 August 2009 15:25:23 Chet Ramey wrote:
> Yang Zhang wrote:
> > Why does assigning to multiple variables on the same line exhibit
> > sequential consistency normally but not for local variables?
>
> Because `local' is a command, and word expansion is performed on its
> arguments before it's invoked.  This means the expansion is performed
> before `local' performs the assignment (local sees two arguments:
> `a=x' and `b=').  Variable assignments by themselves behave differently --
> expansion and assignment are done at the same time.

i dont think word expansion occurs first, otherwise wouldnt this break:
foo() {
        unset b c
        f="a b="
        local a=$f c=
        echo a:$a
        echo b:${b+set}
        echo c:${c+set}
}

it certainly works with bash, as does `declare` ... that is, we see:
a:a b=
b:
c:set
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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