Search code examples
grepreturnmatch

grep return 0 if no match


Is there any bash script which can return me a result=true with command grep?

Example: There are 1000 records of 103.12.88 in my CF logs. Can I do a grep 103.12.88 if detect 1 or more results then print/output result show me either YES or True


Solution

  • The actual answer to this question is to add || true to the end of the command, e.g.:

    echo thing | grep x || true
    

    This will still output a 0 return code.