Use the
id
[
^] command, discard any output and check only the exit status. The status is 0 if the username already exists in the user database, 1 if it doesn't exist.
For example, assuming the name to be tested is in the variable $NEWUSER
id $NEWUSER &> /dev/null
if [ $? -eq 0 ]
then
echo "user $NEWUSER arlready exists"
else
echo "$NEWUSER is a new name"
fi