Word splitting and IFS
How it works
Word splitting examines the unquoted results of parameter, command and arithmetic expansion, not ordinary literal words that were already parsed. IFS controls delimiters: if unset, the default is space, tab and newline; if empty, splitting is disabled (unquoted implicit null arguments may still disappear). IFS whitespace is treated differently from non-whitespace delimiters: repeated adjacent non-whitespace delimiters can create empty fields. A final non-whitespace delimiter does not add another trailing field by itself; for example, red: with IFS=: produces one field. After splitting, filename expansion may still occur. Double quotes preserve a scalar value as one argument. Setting IFS in a small standalone script avoids altering your interactive shell.
Run each example separately in a noninteractive Bash 5.2 script in a fresh empty practice directory, with default options and C locale. Output is shown separately; do not enter it as code.
Default splitting
value=' red blue 'set -- $valueprintf '%s\n' "$#"printf '[%s]\n' "$@"Expected stdout:
2[red][blue]Leading and trailing IFS whitespace is ignored; internal runs separate fields.
Non-whitespace separators
IFS=: value='red::blue'set -- $valueprintf '%s\n' "$#"printf '[%s]\n' "$@"Expected stdout:
3[red][][blue]Adjacent colons produce an empty middle field.
Empty IFS
IFS=value='red blue'set -- $valueprintf '%s\n' "$#"printf '[%s]\n' "$@"Expected stdout:
1[red blue]No splitting occurs; the value has no glob characters.
Common mistakes
IFS is not a general CSV parser and disabling splitting does not disable globbing. Quote data unless deliberate splitting is needed; learn structured parsing later.
Practice
For value="one two", use set -- to show the argument count with and without quotes, then explain the difference.
Next: Globbing and filename expansion