寫法一:
----------------------------------------------------------------------------
#!/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='http://images.stylight.de/static/res200/s2870/2870657.1.jpg%0D'#echo ${str##*fo}#echo ${str#fo}while read linedo wget -p ${line:0:59}done < '/root/mysql/mysql.log';