shell读取文件的每一行

写法一:

 

#!/bin/bash
while read line
do
    echo $line
done < filename(待读取的文件)

 

写法二:

#!/bin/bash
cat filename(待读取的文件) | while read line
do
    echo $line
done

写法三:

for line in `cat filename(待读取的文件)`
do
    echo $line
done

for 逐行读会分割行内容

 

posted @ 2019-09-10 19:09  bob_coder  阅读(10307)  评论(0编辑  收藏  举报