LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 848|回复: 1

while do done中变数如何让其之外用

[复制链接]
发表于 2005-12-23 22:29:58 | 显示全部楼层 |阅读模式
cat /tmp/erpnot1 | while read kuser
do
                kyn=0
                cat /tmp/allowerp2 | while read allowuser
                        do
                        if [ "$kuser" == "$allowuser" ] ; then
                        kyn=1
                        fi
                        done

if [ "$kyn" == "0" ]; then
        echo $kuser
fi

done

为了什么变数只能在当前的do done中有效呢?
发表于 2005-12-24 06:05:41 | 显示全部楼层
Post by 河边星星
cat /tmp/erpnot1 | while read kuser
do
                kyn=0
                cat /tmp/allowerp2 | while read allowuser
                        do
                        if [ "$kuser" == "$allowuser" ] ; then
                        kyn=1
                        fi
                        done

if [ "$kyn" == "0" ]; then
        echo $kuser
fi

done

为了什么变数只能在当前的do done中有效呢?

因为Pipe。所有的pipe被认为subshell. 如果你写成for或是while do; done <(input)的形式,就不会这样了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表