Three ways:
1.
While Read line
Do
Done<filename
2.
For line in ' cat filename '
Do
Done
3.
Cat FileName | While Read line
Do
Done
Cases:
Reads data from the Math_file file, outputs the maximum, minimum, and average values
1.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/82/D3/wKioL1diFxKx0eN3AAB3cs5dRes407.png "style=" float: none; "title=" 1.PNG "alt=" Wkiol1difxkx0en3aab3cs5dres407.png "/>
Results:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/82/D4/wKioL1diGGOj40hCAAAQSrkwMGo891.png "title=" 1.PNG " alt= "Wkiol1diggoj40hcaaaqsrkwmgo891.png"/>
2.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/D3/wKioL1diFxOzAAi3AABsy2wW6jg773.png "style=" float: none; "title=" 2.PNG "alt=" Wkiol1difxozaai3aabsy2ww6jg773.png "/>
Results:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/82/D4/wKioL1diGHSC0sn5AAAQSrkwMGo108.png "title=" 1.PNG " alt= "Wkiol1dighsc0sn5aaaqsrkwmgo108.png"/>
Same as the first result, but slightly different, for lines in ' cat filename ' does not need to add code to process the empty line
3.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/82/D4/wKiom1diFf-iOie8AAB0uqVLnAY615.png "style=" float: none; "title=" 3.PNG "alt=" Wkiom1diff-ioie8aab0uqvlnay615.png "/>
Results:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/82/D4/wKioL1diGITwpj2vAAAh6qnGVdE241.png "title=" 3.PNG " alt= "Wkiol1digitwpj2vaaah6qngvde241.png"/>
The result is an error, because cat Math_file the content through the pipeline to line, the execution of the pipeline command will fork out a sub-process, we just changed the value of the variable in the child process, the child process exited, echo in the parent process, the value of the variable is not changed in the parent process, So the value is also 0 of the originally defined
Finish
This article from "Zero Egg" blog, declined reprint!
3 ways to redirect Shell files