Created
December 13, 2011 03:59
-
-
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
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 | |
| 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