Linux shell reads the file method in line loop

Source: Internet
Author: User

Turn http://blog.csdn.net/hittata/article/details/7042779

  1. #/bin/bash
  2. printf "*************************************\n"
  3. echo "cat file Whiel Read line"
  4. Cat Test.txt |while Read line
  5. Do
  6. Echo $line;
  7. Done
  8. printf "*************************************\n"
  9. echo "while read line <file"
  10. While Read line
  11. Do
  12. Echo $line;
  13. Done <test.txt
  14. printf "*************************************\n"
  15. echo "for line in Cat test.txt"
  16. saveifs= $IFS
  17. ifs=$ (echo-en "\ n")
  18. For line in $ (cat test.txt)
  19. Do
  20. Echo $line;
  21. Done
  22. ifs= $SAVEIFS

Note: For line in $ (cat test.txt) when there is a space or tab in the file, be sure to set the IFS variable.

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.