Write a script that reads a CSV of `username,group` and creates the users idempotently.

IntermediateHands-onBash scripting tasks
Answer
#!/usr/bin/env bash
set -euo pipefail
while IFS=, read -r user group; do
  [[ -z "$user" || "$user" == "username" ]] && continue   # skip blanks/header
  getent group "$group" >/dev/null || groupadd "$group"
  if id "$user" &>/dev/null; then
    usermod -aG "$group" "$user"
    echo "updated $user"
  else
    useradd -m -s /bin/bash -G "$group" "$user"
    echo "created $user"
  fi
done < users.csv

Key trick → Check first with id/getent, then act. That makes the script safe to run again, which is the same idea Ansible modules are built on.

All Real-World Interview questions Roadmap: Interview readiness

More on Bash scripting tasks