Skip to content

Instantly share code, notes, and snippets.

@mjambon
Last active July 19, 2018 18:17
Show Gist options
  • Save mjambon/7e5a7a0c3f233e3de6e6e80ebf24d762 to your computer and use it in GitHub Desktop.
Save mjambon/7e5a7a0c3f233e3de6e6e80ebf24d762 to your computer and use it in GitHub Desktop.
Scoping of bash functions
#! /bin/bash
f() {
echo "$x"
}
main() {
local x=42
f
}
x=17
main
echo "$x"
@mjambon
Copy link
Author

mjambon commented Jul 19, 2018

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