IFS

noun

say it: “EYE EFF ESS” /ˌaɪˌɛf ˈɛs/

A shell setting that lists the characters, such as spaces, that the shell splits text on.

What is IFS in bash?

IFS (read "I F S", the internal field separator) is the shell variable listing the characters text is split on: a space, a tab and a new line. read also trims them off the ends of a line, so IFS= read -r line, with nothing after the =, keeps each line exactly as written.

while IFS= read -r line; do
  echo "[$line]"       # the spaces at the start stay
done < flight-log.txt

In a sentence

  • “Without IFS=, read trimmed the spaces that IFS lists.”
  • “Setting IFS to nothing kept the two spaces at the start of each line.”

Level: Journeyman · More Unix terms at this level

Updated