Useradd script

Trying to create a bash script that will read the /etc/passwd file for existing UID's before adding a new user and also does an incremental by allocating the next available UID.And also add the user to the correct group.Please help I am a newbie in scripting.

You can try something like this ...

#!/bin/bash
read -p "Enter the username : " x
U=$(( `cat /etc/passwd|cut -d: -f3|sort -nr|head -1` + 1 ))
useradd -u $U $x

it automatically allocates the next available id to the newly created process, if however some users are deleted and their id is free, it will allocate that