管道技巧-while read line

简介:

一 、重定向法;管道法: cat $FILENAME | while read LINE

Function While_read_LINE(){

cat $FILENAME | while read LINE

do

echo $LINE

done

}

         注释:我只所有把这种方式叫做管道法,相比大家应该可以看出来了吧。当遇见管道的时候管道左边的命令的输出会作为管道右边命令的输入然后被输入出来。

二、实例

1、pri.sh

1
2
3
4
5
6
7
#!/bin/bash
 
cat ~/xieco/dirls |  while  read dd
do
   echo  "chown -R test:test ${dd}"
   chown -R deuser:deuser ${dd}
done


2、dirr

1
2
/usr/local/htdocs/dcserver/utilserver/
/usr/local/configs/


3、执行 sh pri.sh










本文转自 zouqingyun 51CTO博客,原文链接:http://blog.51cto.com/zouqingyun/1742803,如需转载请自行联系原作者
目录
相关文章
|
8月前
|
网络协议
av_interleaved_write_frame -32 broken pipe
av_interleaved_write_frame -32 broken pipe
128 0
av_interleaved_write_frame -32 broken pipe
|
9月前
UE Operation File [ Read / Write ] DTOperateFile 插件说明
UE Operation File [ Read / Write ] DTOperateFile 插件说明
38 0
|
存储 Shell
Shell的read 读取控制台输入、read的使用
Shell的read 读取控制台输入、read的使用
Shell的read 读取控制台输入、read的使用