3 ways to redirect Shell files

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.