On 06/27/11 17:49, Ted Unangst wrote:
> On Mon, Jun 27, 2011 at 11:00 AM, Christopher Zimmermann
> <madro...@zakweb.de> wrote:
>> Hi,
>>
>> ksh(1) states this:
>>
>> Functions defined with the function reserved word are treated differently
>>    in the following ways from functions defined with the () notation:
>>
>>    [...]
>>
>>    o   Parameter assignments preceding function calls are not kept in the
>>        shell environment (executing Bourne-style functions will keep
>>        assignments).
>>
>> This does not work for me:
>>
>> $ i=foo
>> $ function fun { echo $i; }
> 
> That doesn't count as an assignment preceding a function call.
> Compare with what happens running the test below.
> 
> function f1 {
>         echo $i;
> }
> f2() {
>         echo $i;
> }
> 
> i=foo
> i=1 f1
> f1
> 
> i=bar
> i=2 f2
> f2

$ function f1 { echo $i; }
$ f2 () { echo $i; }
$ i=foo
$ i=1 f1
1
$ echo $i
foo
$ i=1 true
$ echo $i
foo
$ i=1 f2
1
$ echo $i
1

Ok, I got it. But wtf? Thats creepy! Is there any rationale behind this
strange bourne behaviour?!?

Reply via email to