获取函数返回值的两种方法

来源:互联网 发布:易拉宝分辨率 知乎 编辑:程序博客网 时间:2024/05/16 10:21

方法一: 使用全局变量

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. g_result=""  
  2.   
  3. function testFunc()  
  4. {  
  5.     g_result='local value'  
  6. }  
  7.   
  8. testFunc  
  9. echo $g_result  

方法二: 把shell函数作为子程序调用,将其结果写到子程序的标准输出
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. function testFunc()  
  2. {  
  3.     local_result='local value'  
  4.     echo $local_result  
  5. }  
  6.   
  7. result=$(testFunc)  
  8. echo $result 
0 0
原创粉丝点击