How can I check if 'grep' doesn't have any output?

Just do a simple if like this:

if grep -q $address  /etc/passwd
then 
   echo "OK";
else
   echo "NOT OK";
fi

The -q option is used here just to make grep quiet (don't output...)


Use getent and check for grep's exit code. Avoid using /etc/passwd. Equivalent in the shell:

getent passwd | grep -q valid_user
echo $?

Output:

0

And:

getent passwd | grep -q invalid_user
echo $?

Output:

1

Your piece of code:

if [ -z grep $address /etc/passwd ]

You haven't saved the results of grep $address /etc/passwd in a variable. Before putting it in the if statement and then testing the variable to see if it is empty.

You can try it like this:

    check_address=`grep $address /etc/passwd`
    if [ -z "$check_address" ]
      then
    validuser=0
    else
        validuser=1
    fi