码迷,mamicode.com
首页 > 系统相关 > 详细

shell 管道导致的变量重置问题

时间:2019-05-15 14:08:34      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:archive   脚本   bsp   shell 管道   参考   重置   shell   测试   www.   

测试脚本:

#!/bin/sh

flag=0

func() {

    flag=1
    echo 123
}

main() {

    func | grep 123
    echo "flag=$flag"
}

输出显示的flag=0!

 

参考:https://www.cnblogs.com/super119/archive/2010/12/18/1909829.html

shell 管道导致的变量重置问题

标签:archive   脚本   bsp   shell 管道   参考   重置   shell   测试   www.   

原文地址:https://www.cnblogs.com/laymond/p/10868951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!