Check if a variable is having value

I have a script /root/asas with following contents.

#!/bin/bash

ha=`cat /etc/passwd | grep sandra`

if [ -n $ha ]; then
        echo "Sandra is in /etc/passwd"
        echo "variable ha is $ha"
else
        echo "Sandra is NOT in /etc/passwd"
        echo "variable ha is $ha"

fi

What I need is when "cat" does not find sandra in /etc/passwd, it should print "Sandra is NOT in /etc/passwd". But this is not giving correct result. See below.

[root@server ]# grep sandra /etc/passwd
#sandra

[root@server ]# sh /root/asas
Sandra is in /etc/passwd
variable ha is #sandra

[root@server ]# grep sandra /etc/passwd  --> sandra removed from /etc/passwd

[root@server ]# sh /root/asas
Sandra is in /etc/passwd  --> supposed to be "Sandra is NOT in /etc/passwd"
variable ha is

If you just want to print Sandra is NOT in /etc/passwd" then why are you using " echo "variable ha is $ha" in else of your script?

Try this

#!/bin/bash
more /etc/passwd | grep "sandra" 2>/dev/null
if [ "$?" = "0" ]; then
echo "FOUND"
else
echo "NOT FOUND"
fi

Change

if [ -n $ha ]; then

to
either

if [ -n "$ha" ]; then

or

if [[ -n $ha ]]; then

.
There are at least a couple of improvements needed in your "script".