方法一: 使用全局变量
g_result=""
function testFunc()
{
g_result='local value'
}
testFunc
echo $g_result
方法二: 把shell函数作为子程序调用,将其结果写到子程序的标准输出
function testFunc()
{
local_result='local value'
echo $local_result
}
result=$(testFunc)
echo $result
看到一篇关于函数返回值的好文章,分享一下: http://www.linuxjournal.com/content/return-values-bash-functions