Q:

Global variables and information security

I get the impression that it is a programming best practice to create variables in specific scopes (like a function scope) and avoid global scope to make things more modular and better organized.  However I'm not sure if there is also a security issue.
Here is an example of global variables in Bash that worked for me fine more than a year:
cat <<-EOF >> "$HOME"/.profile
    set -x
    complete -r
    export war="/var/www/html" # Web Application Root;
    export dmp="phpminiadmin" # Database Management Program;

    export -f war
    war() {
        cd $war/
    }
EOF

source "$HOME"/.profile 2>/dev/null

I have never had a problem with global variables in Bash or JavaScript, most likely because I only wrote small scripts for personal usage on minimalist environments.
Why do many programmers avoid using global variables and are there any examples of security breaches caused by using global variables?

A:

Boycott Globals!
I'm stealing from Steffen Ullrich's comment, but the main issue with global variables is that they make it difficult to keep code well organized and maintainable.  His link is a fine one, but you won't have any trouble finding countless articles about the problems with global variables online.
When you use global variables, it becomes easy to lose track of where in your program the variable gets modified, especially if you don't have a simple linear flow.  As a result global variables can work perfectly fine in small scripts, but can cause massive headaches as an application begins to scale.
The main reason why I would avoid globals is because they make automated unit/integration testing a nightmare.  Small applications can survive without tests, but trying to manage a larger application without good tests is just a nightmare (trust me, I tried in my young-and-foolish days).
This might leave you with the impression that globals are fine in very small applications, but since applications usually only grow over time, and things that start off temporary become permanent, it's really just a bad idea to use them at all.  Why start on the wrong foot, when it is so easy to use properly scoped variables?
Security
Using global variables doesn't have any direct implications for security, but they do make it easier to end up with security issues:
If a programmer modifies a function in file A but doesn't know or forgets that the value for a certain variable in that function comes from user input in file B, it might end up doing insecure things on user input without proper safe guards.
Global Variables == death
I don't know of any breaches that happened specifically because of global variables, but it's easy to argue that the use of global variables has literally killed people, so I think it's reasonable to just never use them.

A:

In some programming environments, you can't trust the global scope since other sources could read / mess with it.
This has already led to some critical vulnerabilities in security sensitive products, like a remote code execution in the LastPass browser extension.

A:

They can give code injections easier access to everything
In PHP there is the $GLOBALS superglobal; in Python there is the globals() function, and in Javascript there is the window (or in Node, process) object. These all make it trivial to enumerate all global variables.
Once you do that you can both suck out the information they contain and change them maliciously. For example, if sensitive data is stored in a global, an attacker could easily extract it. If, say, a database connection URL is stored in a global, an attacker could point the URL to refer to the attacker's server instead, and then the victim would attempt to connect to that server and send credentials.
Also, if you have a lot of global objects then you can call their methods with ease.
They violate "principle of least privilege"
This principle of security engineering basically says "don't give someone more access than they need in order to do their job". Every function and method can read and write global variables even if they are totally irrelevant to its job, which means that if that piece of code is hijacked even in some limited way, it will open up a greater attack surface.
(Of course, most scripting languages have weak encapsulation rules which is also a violation of POLP, but if objects are out of scope then it is a lot harder to do anything to them.)
They are a breeding ground for buggy code
For reasons including:

the programmer forgetting that one of the variables in a function is a global and thus changes made to it will persist when the function ends,
the non-obvious sensitivity of the program to the order in which functions are called
the ease with which cascade failures can happen (e.g. when a function sets a global to null and later another one crashes)
the highly complex interactions which can easily occur and are hard to reason about

They are simply untidy
If you think about a business where there are papers strewn everywhere, things aren't organised and filed away neatly but just lying around, who's going to notice if something goes missing? If an employee commits fraud nobody will spot the discrepancy because discrepancies are everywhere. If a pair of keys goes missing, someone will just assume they're buried under something or someone had to borrow them.
Now you might say this is an exaggeration, but if so I doubt you've ever worked with a big software project. Globals are OK if your website is small enough to build in a couple of days (and you know what you're doing). They can save time to get something going.
But they don't scale.

