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

Is there a better way today?

Wouldn't it be a valuable feature to add to a shell interpreter on shopt 
or something, to have all shell functions create local variables rather 
than global by default?

Followups directed to comp.unix.shell.


Reply via email to