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

shell:读取文件的每一行内容并输出

时间:2019-11-03 10:25:06      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:写法   class   管道   读取文件   bin   while   col   内容   管道命令   

写法一:输入重定向

1 #!/bin/bash
2 
3 while read line
4 do
5     echo $line
6 done < file(待读取的文件)

 

写法二:管道命令

1 #!/bin/bash
2 
3 cat file(待读取的文件) | while read line
4 do
5     echo $line
6 done

 

写法三:

1 for line in `cat file(待读取的文件)`
2 do
3     echo $line
4 done

 

shell:读取文件的每一行内容并输出

标签:写法   class   管道   读取文件   bin   while   col   内容   管道命令   

原文地址:https://www.cnblogs.com/FengZeng666/p/11785149.html

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