2013年3月6日 星期三

bash script return value



http://www.linuxjournal.com/content/return-values-bash-functions

1.  return a value from a bash function is to just set a global variable to the result.
     // the simplest way s
ince all variables in bash are global by default 


function myfunc()
{
    myresult='some value'
}

myfunc
echo $myresult




2.  command substitution


function myfunc()
{
    local  myresult='some value'
    echo "$myresult"
}

result=$(myfunc)   # or result=`myfunc`
echo $result

沒有留言:

張貼留言