# Input Field Separators

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Input_Field_Separators
> Markdown URL: https://mediated.wiki/source/Input_Field_Separators.md
> Source: https://en.wikipedia.org/wiki/Input_Field_Separators
> Source revision: 1171870549
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

For many command line interpreters (“shell”) of '''[Unix](/source/Unix)''' [operating system](/source/operating_system)s, the '''input field separators''' or '''internal field separators''' or '''{{tt|$IFS}}''' [shell variable](/source/Environment_variable) holds characters used to separate text into tokens.

The value of {{mono|IFS}}, (in the bash shell) typically includes the [space](/source/space_character), [tab](/source/tab_character), and the [newline](/source/newline) characters by default. These whitespace characters can be visualized by issuing the "declare" command in the bash shell or printing {{mono|IFS}} with commands like <code>printf %s "$IFS" | od -c</code>, <code>printf "%q\n" "$IFS"</code> or <code>printf %s "$IFS" | cat -A</code> (the latter two commands being only available in some shells and on some systems).

From the [Bash](/source/Bash_(Unix_shell)), version 4 [man page](/source/man_page):

<blockquote>
The shell treats each character of {{mono|$IFS}} as a [delimiter](/source/delimiter), and splits the results of the other expansions into words on these characters.
If {{mono|IFS}} is unset, or its value is exactly {{mono|&lt;space&gt;&lt;tab&gt;&lt;newline&gt;}}, the default, then sequences of {{mono|&lt;space&gt;}}, {{mono|&lt;tab&gt;}}, and {{mono|&lt;newline&gt;}} at the beginning and end of the results of the previous expansions are ignored, and any sequence of {{mono|IFS}} characters not at the beginning or end serves to delimit words.
If {{mono|IFS}} has a value other than the default, then sequences of the whitespace characters {{mono|space}} and {{mono|tab}} are ignored at the beginning and end of the word, as long as the whitespace character is in the value of {{mono|IFS}} (an {{mono|IFS}} whitespace character).
Any character in {{mono|IFS}} that is not {{mono|IFS}} whitespace, along with any adjacent {{mono|IFS}} whitespace characters, delimits a field. A sequence of {{mono|IFS}} whitespace characters is also treated as a delimiter. If the value of {{mono|IFS}} is null, no word splitting occurs.
</blockquote>

== IFS abbreviation ==
According to the Open Group Base Specifications, {{tt|IFS}} is an abbreviation for "input field separators."<ref>{{Cite web|last=|first=|date=2004|title=Shell Command Language|url=https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_05_03|access-date=2020-10-12|website=pubs.opengroup.org}}</ref> A newer version of this specification mentions that "this name is misleading as the IFS characters are actually used as field terminators."<ref>{{Cite web|title=sh|url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html#tag_20_117_18|access-date=2020-10-12|website=pubs.opengroup.org}}</ref> However {{tt|IFS}} is often referred to as "internal field separators."

== Exploits ==
IFS was usable as an exploit in some versions of Unix. A program with root permissions could be fooled into executing user-supplied code if it ran (for instance) <code>system("/bin/mail")</code> and was called with {{mono|$IFS}} set to {{mono|"/"}}, in which case it would run the program "{{mono|bin}}" (in the current directory and thus writable by the user) with root permissions.<ref>{{cite web |url=http://www.win.tue.nl/~aeb/linux/hh/hh-8.html#ss8.7 |title = Hackers Hut: Environment variables}}</ref> This has been fixed by making the shells not inherit the IFS variable.

==References==
{{reflist}}

Category:Unix

{{compsci-stub}}

---
Adapted from the Wikipedia article [Input Field Separators](https://en.wikipedia.org/wiki/Input_Field_Separators) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Input_Field_Separators?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
