I know that read
command splits the input by the characters in the IFS. So if I set IFS as a space then input to the read
command is split using space as the delimiter. This is shown below.
[[email protected] ~]$ IFS=" "
[[email protected] ~]$ read a b c
foo bar baz qux
[[email protected] ~]$ echo "$a"
foo
[[email protected] ~]$ echo "$b"
bar
[[email protected] ~]$ echo "$c"
baz qux
I was expecting that if I make change the IFS to a non-whitespace character, say, a colon and use colon as delimiter in my input, there should be no change in behaviour. But this turned out to be wrong. For example, in the output below, echo "$a"
is blank. Why?
[[email protected] ~]$ IFS=:
[[email protected] ~]$ read a b c
:foo:bar:baz:qux
[[email protected] ~]$ echo "$a"
[[email protected]tos ~]$ echo "$b"
foo
[[email protected] ~]$ echo "$c"
bar:baz:qux
[[email protected] ~]# echo $c
bar baz qux
And why does the output of echo $c
does not contain the colons?