#!/bin/bash
# Read and Display all Users from /etc/passwd

# Set PATH to something useful
PATH="/usr/local/sbin:/usr/local/bin:/usr/gnu/bin:/sbin:/bin:/usr/sbin:/usr/bin"

# File to read
infile="/etc/passwd"

# Print header line
printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "user" "uid" "gid" "comment" "homedir" "shell"

while read -r line; do
	# Ignore lines starting with '#'
	if [ "${line:0:1}" != "#" ]; then
		user=`echo "$line" | cut -d':' -f1`
		uid=`echo "$line" | cut -d':' -f3`
		gid=`echo "$line" | cut -d':' -f4`
		comment=`echo "$line" | cut -d':' -f5`
		homedir=`echo "$line" | cut -d':' -f6`
		shell=`echo "$line" | cut -d':' -f7`
		
		printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "$user" "$uid" "$gid" "$comment" "$homedir" "$shell"
	fi
done < $infile
