This is documented in man bash
. A single occurrence of any character in IFS that is not whitespace delimits a field.
From man bash
:
The shell treats each character of IFS as a delimiter, and
splits the results of the other expansions into words using these
characters as field terminators. If IFS is unset, or its value is
exactly <space><tab><newline>
, the default, then sequences of <space>
,
<tab>
, and <newline>
at the beginning and end of the results of the
previous expansions are ignored, and any sequence of IFS
characters not at the beginning or end serves to delimit words. If
IFS has a value other than the default, then sequences of the
whitespace characters space, tab, and newline are ignored at the
beginning and end of the word, as long as the whitespace character is
in the value of IFS (an IFS whitespace character). Any
character in IFS that is not IFS whitespace, along with any adjacent
IFS whitespace characters, delimits a field. A sequence of IFS
whitespace characters is also treated as a delimiter. If the value
of IFS is null, no word splitting occurs. [Emphasis added.]
Examples: field splitting
If IFS has no whitespace characters, then whitespace is included in the fields:
$ ( IFS=',' x='one , two,three'; printf "<%s>\n" $x )
<one >
< two>
<three>
If IFS has both blanks and a comma, then sequences of blanks, followed by a comma, followed by sequences of blanks are treated as a single delimiter:
$ ( IFS=' ,' x='one , two,three'; printf "<%s>\n" $x )
<one>
<two>
<three>
Sequences of commas are interpreted as sequences of empty fields:
$ ( IFS=' ,' x='one,,,two,three'; printf "<%s>\n" $x )
<one>
<>
<>
<two>
<three>
Examples: leading and trailing whitespace
If IFS contains no whitespace, then any leading and trailing whitespace is kept in the fields:
$ ( IFS=',' x=' one , two,three ,'; printf "<%s>\n" $x )
< one >
< two>
<three >
If IFS does contain blanks, then any leading or trailing sequences of blanks are removed:
$ ( IFS=' ,' x=' one , two,three ,'; printf "<%s>\n" $x )
<one>
<two>
<three>