04. 1.
由于使用for来读入文件里的行时,会自动把空格和换行符作为一样分隔符,因为当行里有空格的时候,输出的结果会很乱,所以……
cat line.txt |while read i
> do
> echo $i
> done
或者:
while read i
> do
> echo $i
> done < line.txt
再举个实际点的例子(把所有目录权限修改为755,所有文件为644):
# find ./ -type f>filelist
# find ./ -type d>dirlist
# cat dirlist |while read i; do chmod 755 "${i}"; done
# cat filelist |while read i; do chmod 644 "${i}"; done
07. 13.
Bash While Loop Example - Bash While 循环实例
Q. How do I use bash while loop to repeat certain task under Linux / UNIX operating system?
A. Bash while loop is a control flow statement that allows code or commands to be executed repeatedly based on a given condition. For example, run echo command 5 times or read text file line by line or evaluate the options passed on the command line for a script.
while loop syntax
阅读全文 »
hao32