shell读取文件的每一行写法
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逐行读和while逐行读是有区别的,如:
$ cat file
1111
2222
3333 4444 555
$ cat file | while read line; do echo $line; done
1111
2222
3333 4444 555
$ for line in $(<file); do echo $line; done
1111
2222
3333
4444
555
上一篇: 牛肉如何炖出来口感鲜嫩好吃
下一篇: 刺泡怎么做好吃,这些小甜点你会做吗