global variable
A variable defined at the top level of a program or module, shared by all the code in that process.
In more detail
Every function can read it; Bash variables are global unless declared local, while Python needs the global statement before a function can assign to one. Globals make it easy for one part of a program to change a value another relies on without anyone noticing, so pass values as arguments instead and keep globals for constants. Each process holds its own copy, and a restart resets it.
Example
HITS = 0 # VI: request state lives in the process, and dies with itRelated terms
- local variable — A variable that exists only inside one function call and cannot be seen or changed from outside it.
- readonly builtin — The builtin that makes a variable unchangeable for the rest of the shell's life, used for constants.
- dynamic scoping — Bash's rule that a function can see the local variables of whichever function called it, not only globals.
- stateless process — A process that keeps nothing it needs between requests in its own memory or disk, so it can be restarted or replaced at any moment.
- mutex — A lock that lets only one piece of code at a time run a critical section or do a particular piece of work.
- constant — A name for a value that is set once and is not meant to change while the program runs.
- scope — The region of a program where a name can be seen and used.
Taught in
- Functions, local And declare — Bash Scripting & Command Line Automation
- Style That Prevents Bugs — Bash Scripting & Command Line Automation
- Build, Release, Run And Processes — DevOps & Site Reliability Engineering
- Local Scope And Global Constants — Hands-on Python: Complete Video Course & Book
- Parameters, Arguments And Scope — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Closures: Functions That Remember — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep