On Fri, Jul 25, 2008 at 2:07 AM, Dan Stromberg
<[EMAIL PROTECTED]> wrote:
>
> Having a shell function's variable changes reflected in its caller really
> kinda makes me shudder - in fact, it reminds me of gosub. It seems like
> a bug waiting to happen; I'm amazed I haven't been bitten by it yet.
>
> It occurred to me that this might help - but of course it's probably
> quite a bit slower:
>
> #!/bin/sh
>
> function fn
> {(
> variable=2
> )}
>
> variable=1
> fn
> echo $variable
This script is wrong, you should not use the form "function fn" with
sh, it is not defined by posix (you also don't need the { } )
fn ()
(
variable =2
)
> Is there a better way today?
With "sh" (a posix shell) no
In bash you can use the builtin "local" (or declare).