title: grep, else print message for no matches
body: <p>In a bash script, I have a list of lines in a file I wish to grep and then display on standard out, which is easiest done with a while read:</p>
  
  <pre><code>grep "regex" "filepath" | while read line; do
      printf "$line\n"
  done
  </code></pre>
  
  <p>However, I would like to inform the user if no lines were matched by the grep. I know that one can do this by <a href="http://mywiki.wooledge.org/BashFAQ/024" rel="noreferrer">updating a variable inside the loop</a> but it seems like a much more elegant approach (if possible) would be to try to read a line in an until loop, and if there were no output, an error message could be displayed.</p>
  
  <p>This was my first attempt:</p>
  
  <pre><code>grep "regex" "filepath" | until [[ -z ${read line} ]]; do
      if [[ -z $input ]]; then
         printf "No matches found\n"
         break
      fi
      printf "$line\n"
  done
  </code></pre>
  
  <p>But in this instance the read command is malformed, and I wasn't sure of another way the phrase the query. Is this approach possible, and if not, is there a more suitable solution to the problem?</p>