IFS
The internal field separator: a shell variable listing the characters that word splitting and read cut text at.
In more detail
Its default is a space, a tab and a newline. Setting it just in front of a command, as in IFS== read -r key value, changes it for that command only. IFS= with nothing after the equals sign stops read from trimming leading and trailing spaces.
Example
while IFS= read -r line; do printf '%s\n' "$line"; done < file.txtRelated terms
- word splitting — The step where bash cuts the result of an unquoted expansion into separate words at spaces, tabs and newlines.
- read builtin — The bash builtin that reads one line of input and stores it, or its fields, in variables.
- whitespace — Characters that show as blank space, such as spaces, tabs and line breaks.
Taught in
- The Unquoted Variable: Splitting And Globbing — Bash Scripting & Command Line Automation
- The Field Separator, And Reading Lines Safely — Bash Scripting & Command Line Automation
- Arrays, And Why Dollar At Is Not Dollar Star — Bash Scripting & Command Line Automation
- Reshaping Text: cut, sort, uniq, tr, sed, awk — Bash Scripting & Command Line Automation
- Script Input And Output: read, Heredocs, printf — Bash Scripting & Command Line Automation
- Arguments: Dollar One, Dollar At, shift — Bash Scripting & Command Line Automation
- Debugging: set -x, bash -n And Reading The Error — Bash Scripting & Command Line Automation
- The Cleanup That Emptied The Wrong Directory: Shell Scripts Under Exam Conditions — CompTIA Linux+ (XK0-006) Exam Prep