首页 > 系统服务 > 详细

linux shell 按行循环读入文件方法

时间:2014-08-09 15:34:58      阅读:465      评论:0      收藏:0      [点我收藏+]

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 

注意:for line in $(cat test.txt)   当文件中有空格或者tab 时,一定要设置一下IFS变量。

linux shell 按行循环读入文件方法,布布扣,bubuko.com

linux shell 按行循环读入文件方法

原文:http://www.cnblogs.com/alex-blog/p/3900896.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!