IFS) is a special shell variable that defines how Bash—and other POSIX-compatible shells—split strings into fields. While environment variables provide static, system-wide settings, shell variables like IFS are dynamic and scoped to your shell session. Properly managing IFS enhances portability by ensuring your scripts behave consistently across different systems.

IFS includes space, tab, and newline. This default behavior impacts many common tasks, such as iterating over lists of filenames or parsing command output.
Table of Default IFS Separators
| Separator | Escape Sequence | Description |
|---|---|---|
| Space | <space> | Splits on spaces |
| Tab | \t | Splits on tabs |
| Newline | \n | Splits on newlines |
Default IFS in Action
Consider a simple Bash script that iterates over a space-separated list:elements splits on spaces by default, each word becomes its own iteration.
Customizing IFS with ANSI-C Quoting
To explicitly redefineIFS to include space, tab, and newline, use ANSI-C quoting:
The
$'…' syntax tells Bash to process backslash escapes within single quotes, ensuring you include the exact characters you need.
Changing the Field Separator
If your data uses a different delimiter—such as a colon (:)—override IFS before expanding variables. Without overriding, the string remains intact:
IFS to a colon:
Changing
IFS globally can affect subsequent commands and scripts. Always restore it to its default value after making temporary adjustments.IFS and Literal Strings
IFS only applies when expanding variables. Looping over a quoted literal string bypasses field splitting:
IFS has no effect.
Interactive IFS Changes
You can also reassignIFS directly in your interactive shell session:
set -- ${val} replaces the shell’s positional parameters with the split values of val.
Restoring IFS and Handling Empty Strings

-
Restore IFS to default
This command works in Bash, Zsh, and KornShell. Older shells might require specialized syntax.
-
Set IFS to an empty string
When
IFSis empty, no field splitting occurs—every expansion remains as a single, unsplit string.