shell分割IFS

一个文件file,内容: 

hello this is a word
i have a apple
do you want one

如果这是读取文件,输出每行

for cont in `cat file`
do
   echo $cont
done

输出内容会是这样的

hello
this
is
a
word
i
have
a
apple
do
you
want
one

要想按行输出,要在脚本前面加上这句,重新定义IFS变量

IFS=$'
'
介绍

IFS=‘ ’  //将字符n作为IFS的换行符。

IFS=$" " //这里 确实通过$转化为了换行符,但仅当被解释时(或被执行时)才被转化为换行符。

IFS=$' ' //这才是真正的换行符。

原文地址:https://www.cnblogs.com/jkklearn/p/8185986.html