How does IFS split a string in shell

17 Views Asked by At

I change IFS to :

When I use the string "abc:xyz:jkl" directly, the for loop only iterates once. The string is not split.

IFS=:
for i in abc:xyz:jkl
do
    echo $i
done

But when I store the value in a variable, the string is split and the loop iterates three times.

IFS=:
var="abc:xyz:jkl"
for i in $var
do
    echo $i
done

Another similar question is, when I have the IFS as default, for i in "abc xyz jkl" and var="abc xyz jkl; for i in $var" also run differently.

0

There are 0 best solutions below