Interview Prep/Shell Scripting/Variables, quoting and expansions

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions