shell 里 使用while 循環行讀取文件


使 用while 循環逐行讀取文件內容



使用 set 命令查看當前shell變量

linux 里 分隔符保存在 變量 "IFS" 里,默認的分隔符空格"" ; 制表符 \t ; 換行符 \n

[root@host103 test]# set |grep IFS

image-20210716083856595



使用for 循環讀取文件內容

當文件中有空格時,直接使用for 循環就會分隔開內容

image-20210716084222119

image-20210716084331761


使用while read ,行讀取文件

使用while read 命令讀取文件,目標文件內容以 重定向輸入的形式輸入

方法一

[root@host103 test]# while read  line    
> do
> echo "$line"
> done < /test/users.txt

image-20210719082405415



方法二

[root@host103 test]# cat users.txt  | while read line
> do
> echo "$line"
> do

image-20210719083140861


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM