Created
September 4, 2014 18:36
-
-
Save chawkinsuf/9f17fbf34ef1d6512afa to your computer and use it in GitHub Desktop.
Return values from bash functions
This file contains 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
return_value() | |
{ | |
local _variable_="${!1}" | |
local _other_="other value" | |
# Make a default value if the variable passed was empty | |
if [ -z "$_variable_" ]; then | |
_variable_="default" | |
fi | |
# Return variable | |
if [ -n "$1" ]; then | |
eval "$1="$_variable_"" | |
fi | |
# Return other | |
if [ -n "$2" ]; then | |
eval "$2="$_other_"" | |
fi | |
} | |
variable= | |
return_value variable other | |
echo "$variable" | |
echo "$other" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment