Skip to content

Instantly share code, notes, and snippets.

@chawkinsuf
Created September 4, 2014 18:36
Show Gist options
  • Save chawkinsuf/9f17fbf34ef1d6512afa to your computer and use it in GitHub Desktop.
Save chawkinsuf/9f17fbf34ef1d6512afa to your computer and use it in GitHub Desktop.
Return values from bash functions
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