管道技巧-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,如需转载请自行联系原作者
目录
相关文章
|
2月前
|
Linux 开发者
Linux文件编程(open read write close函数)
通过这些函数,开发者可以在Linux环境下进行文件的读取、写入和管理。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
124 4
|
2月前
|
Linux
内核态的文件操作函数:filp_open、filp_close、vfs_read、vfs_write、set_fs、get_fs
内核态的文件操作函数:filp_open、filp_close、vfs_read、vfs_write、set_fs、get_fs
228 0
|
9月前
|
存储 缓存
【什么是Read Write Through机制】
【什么是Read Write Through机制】
|
11月前
|
Python
轻松读取大文件:Python中read()、readline()和readlines()技巧大揭秘
轻松读取大文件:Python中read()、readline()和readlines()技巧大揭秘
155 0
UE Operation File [ Read / Write ] DTOperateFile 插件说明
UE Operation File [ Read / Write ] DTOperateFile 插件说明
50 0
|
存储 Linux Python
Python文件相关知识点strip、open、read、write、close、readline、readlines、encoding、encode、decode
文件的作用: 可以永久的保存数据. 文件在硬盘中存储的格式是二进制. 打开文件 读写文件 关闭文件 打开文件, 是文件从硬盘中存到内存中 open(file, mode=‘r’, encoding) file 要操作的文件名字, 类型是 str mode, 文件打开的方式, r(read) 只读打开, w(write) 只写打开 a(append) 追加打开 encoding 文件的编码格式, 常见的编码格式有两种, 一种是gbk, 一种是utf-8 返回值, 文件对象, 后续所有的文件操作,都需要通
312 1
Python文件相关知识点strip、open、read、write、close、readline、readlines、encoding、encode、decode
|
存储 Shell
Shell的read 读取控制台输入、read的使用
Shell的read 读取控制台输入、read的使用
Shell的read 读取控制台输入、read的使用
open函数: 可以帮助我们获取文件对象 内置函数 open(file, mode='r', buffering=-1, encoding=None, errors=None
open函数: 可以帮助我们获取文件对象 内置函数 open(file, mode='r', buffering=-1, encoding=None, errors=None