Last active
July 19, 2018 18:17
-
-
Save mjambon/7e5a7a0c3f233e3de6e6e80ebf24d762 to your computer and use it in GitHub Desktop.
Scoping of bash functions
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 | |
f() { | |
echo "$x" | |
} | |
main() { | |
local x=42 | |
f | |
} | |
x=17 | |
main | |
echo "$x" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because bash functions execute in their caller's scope.