Monday 14 August 2017

Bash Internal Field Separator

Cited from the Book "Pro Bash Programming"

The results of parameter and arithmetic expansions, as well as command substitution, are subjected to word splitting if they were not quoted.
Word splitting is based on the value of the internal field separator variable, IFS. The default value of IFS contains the whitespace characters of space, tab, and newline (IFS=$' \t\n'). When IFS has its default value or is unset, any sequence of default IFS characters is read as a single delimiter.

If IFS contains another character (or characters) as well as whitespace, then any sequence of
whitespace characters plus that character will delimit a field, but every instance of a nonwhitespace
character delimits a field.

If IFS contains only nonwhitespace characters, then every occurrence of every character in IFS
delimits a field, and whitespace is preserved.

No comments:

Post a Comment