Skip to content

Instantly share code, notes, and snippets.

@gerrywastaken
Created December 13, 2011 03:59
Show Gist options
  • Select an option

  • Save gerrywastaken/1470498 to your computer and use it in GitHub Desktop.

Select an option

Save gerrywastaken/1470498 to your computer and use it in GitHub Desktop.
Demonstrating how to call a function in Bash that updates a global without the global actually getting updated. =P
#!/bin/bash
testGlobal=0;
updateGlobal(){
testGlobal=50;
echo "World!";
}
#Output the return value directly
echo "Hello $(updateGlobal)"; # Output: Hello World!
echo $testGlobal; # Global is 0
#Output the return value indirectly
echo -n "Hello "; updateGlobal; #Output: Hello World
echo $testGlobal; # Global is 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment