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










