Interview Prep/Shell Scripting/Arrays, conditionals and loops

How do you process a CSV file line by line into fields?

IntermediateConceptArrays, conditionals and loops
Answer
while IFS=, read -r username group shell _rest; do
  [[ -z $username || $username == \#* ]] && continue   # skip blanks and comments
  echo "user=$username group=$group shell=${shell:-/bin/bash}"
done < <(tail -n +2 users.csv)                         # skip the header

The last variable receives the remainder of the line, so add _rest to absorb extra columns. This only handles simple CSV: quoted fields with embedded commas need a real parser (python3 -c 'import csv...', mlr, or csvkit).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops