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



    Date:        Tue, 26 Feb 2013 12:33:25 +0100
    From:        tlaronde%polynum.com@localhost
    Message-ID:  <20130226113325.GA3490%polynum.com@localhost>

  | Are you using /bin/sh ?

Yes.

  | $ cat /tmp/essai.sh
  | #!/bin/sh
  | 
  | f() { echo $foo; }
  | foo=bar
  | f
  | foo=XXX f

That looks like a bug (a different one) - the only explanation for
that is that in ...

        f() { echo $foo; }

$foo is being expanded during the function definition (which is not
supposed to happen, I believe).   Note that I had ...

f() { echo "$foo" }

so I guess the quotes changed things (they shouldn't).

  | Did I misread your mail?

No.   But your test (if it was correct) would make functions
completely useless, so there had to be some other explanation.

I have since also tested this with (almost) current (6.99.16) amd64
and that works just the same as 6.0 i386 (which I'd expect, as I
think the way it works is right), and using ksh which (unsurprisingly
perhaps) acts the way I read the SUS.   bash looks to be the same as
NetBSD's sh.

For completeness ...

eos$ cat t.sh
#! /bin/sh

f()
{
        echo "${foo}"
}

foo=before
f
foo=during f
f
foo=after
f


And then ...

eos$ sh t.sh
before
during
before
after
eos$ ksh t.sh
before
during
during
after
eos$ bash t.sh
before
during
before
after

(those all from 6.0/i386).

kre



Home | Main Index | Thread Index | Old Index