The docs that are Very Wrong:
A variable declared as local is one that is visible only within the block of code in which it appears. It has local scope. In a function, a local variable has meaning only within that function block. [1]
#!/bin/bash | |
echo == example the first == | |
f1() { | |
local v=1 | |
echo f1: $v | |
f2 | |
} | |
f2() { | |
echo f2: $v | |
} | |
v=0 | |
f1 | |
echo == example the second == | |
v=0 | |
f1() { | |
local v=1 | |
echo f1-pre: $v | |
f2 | |
echo f1-post: $v | |
} | |
f2() { | |
v=2 | |
} | |
f1 | |
echo global: $v |
The docs that are Very Wrong:
A variable declared as local is one that is visible only within the block of code in which it appears. It has local scope. In a function, a local variable has meaning only within that function block. [1]