What is `IFS` and how does it affect your script?
IntermediateConceptVariables, quoting and expansions
Answer
IFS (Internal Field Separator, default space, tab, newline) controls how unquoted expansions are split into words and how read splits a line into fields. Its first character also joins "$*".
IFS=: read -r user _ uid gid _ home shell <<<"deploy:x:1001:1001::/home/deploy:/bin/bash"
echo "$user $uid $shell"
IFS=, ; set -- $csv_line ; unset IFS # split once, then restore
Change IFS locally (IFS=, read ...) rather than globally; a global change breaks unrelated code later in the script.
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?Intermediate