bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Variable scoping


From: Dan Stromberg
Subject: Variable scoping
Date: Thu, 24 Jul 2008 23:07:40 GMT
User-agent: Pan/0.132 (Waxed in Black)

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

[Prev in Thread] Current Thread [Next in Thread]