title: How can I check if 'grep' doesn't have any output?
body: <p>I need to check if the recipient username is in file <em>/etc/passwd</em> which contains all the users in my class, but I have tried a few different combinations of <em>if</em> statements and <em><a href="https://en.wikipedia.org/wiki/Grep" rel="noreferrer">grep</a></em> without success. The best I could come up with is below, but I don't think it's working properly.</p>
  <p>My logic behind it is that if the <em>grep</em> is null, the user is invalid.</p>
  <pre><code>send_email()
  {
    message=
    address=
    attachment=
    validuser=1
    until [ &quot;$validuser&quot; = &quot;0&quot; ]
      do
      echo &quot;Enter the email address: &quot;
      read address
      if [ -z grep $address /etc/passwd ]
        then
      validuser=0
      else
          validuser=1
      fi
      echo -n &quot;Enter the subject of the message: &quot;
      read message
      echo &quot;&quot;
      echo &quot;Enter the file you want to attach: &quot;
      read attachment
      mail -s &quot;$message&quot; &quot;$address&quot;&lt;&quot;$attachment&quot;
      done
      press_enter
  }
  </code></pre>