Global variables, and their scope in Bash.

Lachlan Musicman datakid at gmail.com
Mon Dec 14 00:35:25 UTC 2009


On Mon, Dec 14, 2009 at 11:22, Ray Parrish <crp at cmc.net> wrote:
> Hello,
>
> I have a global variable called LoopCount, that I want to access, and
> write to in four different functions. The functions are as follows, [not
> actual code, just showing function names] -
>
> ReadintoArray [
>     # Loop with LoopCount, then reset it to zero.
> }
> WriteTopSection {
>     # Loop with LoopCount, then decrement it one.
> }
.....
> Then perversely the ending value of LoopCount does not get carried
> forward from WriteTopSection to WriteDescriptionSection, but instead is
> once again at the value of zero.

that would be because you are decrementing by 1 as you loop LoopCount times?

> Why in the world can my ReadintoArray function modify the value of the
> global variable LoopCount, but the next function down cannot?
>
> Does anyone have any light they can shed on the behavior of global
> variables in Bash?
>
> Thanks, Ray Parrish
>
>
> The Future of Technology.
> http://www.rayslinks.com/The%20Future%20of%20Technology.html
> Ray's Links, a variety of links to usefull things, and articles by Ray.
> http://www.rayslinks.com
> Writings of "The" Schizophrenic, what it's like to be a schizo, and other
> things, including my poetry.
> http://www.writingsoftheschizophrenic.com
>
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>



-- 
the historian of science looks in vain for a single line of development.

Norbert Wiener.




More information about the ubuntu-users mailing list