Subject: Re: Different behavior w/ and w/o local
To: Julio M. Merino Vidal <jmmv@menta.net>
From: Jachym Holecek <freza@psi.cz>
List: tech-userlevel
Date: 09/14/2003 11:26:02
> f1() {
> 	var=$1
> 	echo $var
> }
> 
> f2() {
> 	local var=$1
> 	echo $var
> }
> 
> And the following calls with their respective output:
> 
> $ f1 "foo bar"
> foo bar
> 
> $ f2 "foo bar"
> foo
> 
> Is this different behavior expected?  I've seen this happens with both /bin/sh
> and /bin/ksh, though there is no mention to this in manpages, afaict.
> Or should I be quoting assignments, like var="$1", to avoid problems?

When I try

f2() {
	local var
	var=$1
	echo $var
}

it works as expected (/bin/sh on 1.6.1). So it looks like a bug (either
in code or in manpage not documenting it).

	Regards,
		-- Jachym Holecek