Bash vars use the dynamic scoping just as in the wiki page you mentioned.
Examples of languages that use dynamic scoping include Logo, Emacs Lisp, and the shell languages bash, dash, and PowerShell.
Dynamic scoping is fairly easy to implement. To find an identifier's value, the program could traverse the runtime stack, checking each activation record (each function's stack frame) for a value for the identifier.
Bash's own manual says this:
The shell uses dynamic scoping to control a variable's visibility
within functions. With dynamic scoping, visible variables and
their values are a result of the sequence of function calls that
caused execution to reach the current function. The value of a
variable that a function sees depends on its value within its
caller, if any, whether that caller is the "global" scope or another
shell function. This is also the value that a local variable
declaration "shadows", and the value that is restored when the
function returns.
For example, if a variable var
is declared as local in function
func1
, and func1
calls another function func2
, references to var
made
from within func2
will resolve to the local variable var
from
func1
, shadowing any global variable named var
.
For how this can be used see Bash: Passing variables by reference.