How to check if grep has no 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 $?
0

> getent passwd | grep -q invalid_user
> echo $?
1

Your piece of code

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

You haven't save 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