Skip to content

Instantly share code, notes, and snippets.

@jneen
Last active December 16, 2015 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jneen/25a944693df3ec92fad7 to your computer and use it in GitHub Desktop.
Save jneen/25a944693df3ec92fad7 to your computer and use it in GitHub Desktop.
#!/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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment