LinuxCommandLibrary

ifs

shell variable controlling word splitting

TLDR

Set field separator

$ IFS=':' read -ra arr <<< "a:b:c"
copy
Split on newline
$ IFS=$'\n'
copy
Save and restore IFS
$ OLD_IFS="$IFS"; IFS=','; ...; IFS="$OLD_IFS"
copy
Default IFS
$ IFS=$' \t\n'
copy

SYNOPSIS

IFS is a shell variable

DESCRIPTION

IFS (Internal Field Separator) is a shell variable controlling word splitting. It defines characters used to split strings into fields.
The default IFS is space, tab, and newline. Changing IFS affects read, for loops, and word splitting behavior.

PARAMETERS

IFS

Internal Field Separator variable.

CAVEATS

Shell variable, not command. Affects word splitting globally. Restore after use.

HISTORY

IFS is a standard POSIX shell variable, present in all Bourne-compatible shells.

SEE ALSO

read(1), bash(1), sh(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community