When you want to save values between functions of your bash script, there are several ways:
- Use the same variable name and don't create them as "local" to a function function myfunc()
{
myresult='some value'
}
myfunc
echo $myresult :!: Quite Dangerous :!:
- Let you function handle arguments: function myfunc()
{
local __resultvar=$1
local myresult='some value'
eval $__resultvar="'$myresult'"
}
myfunc result
echo $result\\
Reference: [[http://www.linuxjournal.com/content/return-values-bash-functions]]