Quantcast
Viewing latest article 1
Browse Latest Browse All 7

Answer by unifex for Can grep return true/false or are there alternative methods

Old post but really the answer was never given.
Yes Grep returns 0 if pattern is found (true) and 1 if the pattern is not found (false).Keep in mind grep is line based so the search term you thought would do it all might give you a lot of garbage hits, I leave this up to you to figure out how to parse.$? is the exit status, I prefer to use pipes rather than reading from a file as it suits my scripts better.I use the following:

{cat/cut/echo/curl/whatever} | grep -q PATTERN |echo $?

If the above returns 0 your pattern was found, if it returns 1 it was not.

This is useful as I place it in while loops to monitor my processes and keep certain scripts alive if they die or notify me if they have completed.


Viewing latest article 1
Browse Latest Browse All 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>