3 ways the shell reads files by line

Source: Internet
Author: User

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

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.