使 用while 循環逐行讀取文件內容
使用 set 命令查看當前shell變量
linux 里 分隔符保存在 變量 "IFS" 里,默認的分隔符是 空格"" ; 制表符 \t ; 換行符 \n
[root@host103 test]# set |grep IFS
使用for 循環讀取文件內容
當文件中有空格時,直接使用for 循環就會分隔開內容
使用while read ,行讀取文件
使用while read 命令讀取文件,目標文件內容以 重定向輸入的形式輸入
方法一
[root@host103 test]# while read line
> do
> echo "$line"
> done < /test/users.txt
方法二
[root@host103 test]# cat users.txt | while read line
> do
> echo "$line"
> do