Shell: Split string while reading from file


2018-02-09

Given the following file

zaiste:admin
zosia:regular
krysia:admin

Use IFS variable (Input Field Separator) shell script to split each line from an input file on : character:

#!/bin/bash

while IFS=':' read -r name role
do
  echo $name
  echo $role
done < users.txt