The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-10-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,767
grep -q returns a status code - the $? thing - of zero when it finds a pattern match and non-zero when it cannot find a pattern match. Otherwise grep returns a line of text.
Not a status.
Code:
grep -q 'something' somefile
if [[ $? -eq 0 ]] ; then
   echo "found it!"
else
   echo "not found."
fi