the shell reads files by line There are many ways to do this, and here are three ways to write:
Writing one:
#!/bin/bash# Description: # while loop read Line operation # Author: Lone Boat Dot # version:1.0#创建时间: -one- Geneva: =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/PATH local/sbin:~/binexport PATH while the readline doecho $line done < filename (files to be read)
Two:
#!/bin/bash# Description: # cat post-read line operation # Author: Lone Boat Dot # version:1.0#创建时间:09 : £º =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/PATH local/sbin:~/binexport PATHcat while read line do Echo $line Done
Three:
#!/bin/bash# Description: # for Loop read line operation, difference from while read Line # Author: Lone Boat Dot # version:1.0#创建时间:11 -Geneva: The=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/PATH bin:/usr/local/sbin:~/binexport PATH for in 'cat filename (file to be read) ' doecho $line Done
Note: The For loop read line operation differs from the while read row
While is read exactly by line, no matter how many paragraphs there are in the line;
For is read by row, if the inline text has a space, it is read separately, reading one string at a time.
3 ways the shell reads files by line