shell-逐行读取文件

代码:

#!/bin/bash

echo 方法1
while read line
do
    echo $line;
done < testdata

echo ""
echo 方法2
cat testdata | while read line
do
    echo $line
done

echo ""
echo 方法3
oldIFS=${IFS};
IFS=$'\n';
for line in $(cat testdata)
do
    echo $line
done
IFS=${oldIFS};

 

文件 testdata:

abc
def
df ab cd
asas

posted @ 2016-10-07 11:55  刨根问底_liang  阅读(4965)  评论(0编辑  收藏  举报