Chinaunix首页 | 论坛 | 博客
  • 博客访问: 783247
  • 博文数量: 108
  • 博客积分: 2887
  • 博客等级: 少校
  • 技术积分: 1570
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-28 07:51
文章分类

全部博文(108)

文章存档

2012年(4)

2011年(86)

2010年(18)

分类: Python/Ruby

2011-04-01 22:03:02

从管道输出到一个read命令中,使用管道echo输出到read会失败,然而使用管道cat输出看起来能够正常的运行

cat file1 file2 |
while read line
do
 echo $line
done



但是:如下面的例子  cat到管道就可能出些问题


有个管道输出到read中的问题:
  1 #!/bin/bash                                                                
  2 #readpipe.sh
  3
  4
  5 last="(null)"
  6
  7 cat $0 |
  8 while read line
  9 do
 10   echo "{$line}"
 11   last=$line
 12 done
 13
 14 printf "\nAll done,last:$last\n"
 15
 16
 17
 18 exit 0
~      



该脚本的输出如下:


{#!/bin/bash}
{#readpipe.sh}
{}
{}
{last="(null)"}
{}
{cat $0 |}
{while read line}
{do}
{echo "{$line}"}
{last=$line}
{done}
{}
{printf "nAll done,last:$lastn"}
{}
{}
{}
{exit 0}

All done,last:(null)


打印出了多余的大括号。



find命令输出到管道:
find $1 \(-name "*$2" -o -name ".*$2"\) -print |
while read f
do
。。。。
done



阅读(3860) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~