LinuxCommandLibrary

ifs

Set the Internal Field Separator variable

TLDR

View the current $IFS value

$ echo "$IFS"
copy

Change the $IFS value
$ IFS="[:]"
copy

Reset $IFS to default
$ IFS=$' \t\n'
copy

Temporarily change the $IFS value in a subshell
$ (IFS="[:]"; echo "[one:two:three]")
copy

SYNOPSIS

No standard syntax; use IFS=chars before shell commands

PARAMETERS

IFS
    Environment variable; set to characters like '<space><tab>\n' for default splitting

DESCRIPTION

The term ifs does not correspond to any standard executable command in Linux distributions or core utilities. It is commonly confused with IFS, the Internal Field Separator environment variable used in POSIX-compliant shells like Bash, Zsh, and others.

IFS controls the delimiter characters for word splitting during command substitution, read builtins, and expansions. By default, IFS is set to space, tab, and newline (" "). Changing it affects how the shell parses strings into words.

For example:
IFS=',' read -r a b <<< '1,2,3'
sets a='1', b='2', leaving 3 in the reply variable.

To view: echo "$IFS" | cat -v
To reset: unset IFS or IFS=$' '.

If ifs refers to a custom script, package-specific tool (e.g., in embedded systems or third-party software), check local man pages or which ifs. No coreutils, util-linux, or busybox equivalent exists.

CAVEATS

Modifying IFS globally affects all subsequent parsing; use local scope (e.g., (IFS=','; ...)) to avoid side effects.
Empty IFS treats entire string as one field.

COMMON USAGE

Loop over CSV: IFS=','; for f in $(cat file.csv); do ...; done
Avoid with while IFS=',' read -r ...; do ...; done < file.

DEBUGGING

Visualize: printf '%q ' "$IFS" or pipe to cat -A.

HISTORY

Originated in original UNIX Bourne shell (1977); standardized in POSIX.1-2008. Evolved with shell enhancements for better quoting and arrays.

SEE ALSO

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

Copied to clipboard