shell:读取⽂件的每⼀⾏内容并输出写法⼀:
----------------------------------------------------------------------------
#!/bin/bash
while read line
do
echo $line
done < file(待读取的⽂件)
----------------------------------------------------------------------------
写法⼆:
----------------------------------------------------------------------------
#!/bin/bash
cat file(待读取的⽂件) | while read line
do
echo $line
done
----------------------------------------------------------------------------
写法三:
----------------------------------------------------------------------------
for line in `cat file(待读取的⽂件)`
do
echo $line
done
-
---------------------------------------------------------------------------
说明:
for逐⾏读和while逐⾏读是有区别的,如:
$ cat file
aaaa
bbbb
cccc dddd
$ cat file | while read line; do echo $line; done
aaaa
bbbb
cccc dddd
并输出
$ for line in $(<file); do echo $line; done
aaaa
bbbb
cccc
dddd
== 实践 ===
#! bin/sh
#$str='images.stylight.de/static/res200/s2870/2870657.1.jpg%0D'
#echo ${str##*fo}
#echo ${str#fo}
while read line
do
wget -p ${line:0:59}
done < '/root/mysql/mysql.log';
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论