Linux:IFS分隔符的使用

IFS分隔符的使用

data="name, gender,rollno,location"
我们可以使用IFS读取变量中的每一个条目。
oldIFS=$IFS
IFS=, #IFS现在被设置为,
for item in $data;
do
echo Item: $item
done
IFS=$oldIFS
输出如下:
Item: name
Item: gender
Item: rollno
Item: location

IFS的默认值为空白字符(换行符、制表符或者空格)。
当IFS被设置为逗号时,shell将逗号视为一个定界符,因此变量 $item 在每次迭代中读取由逗号分隔的子串作为变量值。

原文地址:https://www.cnblogs.com/moox/p/11997832.html