When you want to save values between functions of your bash script, there are several ways:
function myfunc() { myresult='some value' } myfunc echo $myresult
Quite Dangerous
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