Created
July 19, 2018 17:38
-
-
Save mjambon/605f48e3f567e9f8af407e55a7336ed8 to your computer and use it in GitHub Desktop.
Bash scoping. Does this program print 1, 2 or 3?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
x=1 | |
f() { | |
echo "$x" | |
} | |
g() { | |
local x=2 | |
f | |
} | |
x=3 | |
g |
Because bash functions execute in their caller's scope.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It prints