dynamic scoping
Bash's rule that a function can see the local variables of whichever function called it, not only globals.
In more detail
If report declares local i and then calls retry, retry sees and can change report's i unless it declares its own local i. Most programming languages use lexical scoping instead, so this surprises people coming from them.
Related terms
- local variable — A variable that exists only inside one function call and cannot be seen or changed from outside it.
- global variable — A variable defined at the top level of a program or module, shared by all the code in that process.
- shell function — A named group of commands, defined as name() { ...; }, that you then run like any other command.
Taught in
- Functions, local And declare — Bash Scripting & Command Line Automation