3 ms·
The thing I would like to see with grep is to have it optionally give me a 0 return code if it doesn't find anything. I know why the authors chose to use a non
by bradknowles 8y ago
The thing I would like to see with grep is to have it optionally give me a 0 return code if it doesn't find anything.
I know why the authors chose to use a non-zero return code as the default, but when I'm using grep deep in a pipeline and doing my own checking of the results to see if nothing was found, I don't need grep bombing out the whole pipeline with a non-zero return code.
The alternative of being forced to use "(grep pattern||true)" instead of a plain "grep -q" is kinda painful.
- vitorbaptistaa 8y agoI'm not in my computer now, but doesn't "grep -v" solves your issue? If I remember correctly, it inverts the query, so it would return 0 if there wasn't a match.
- Sean1708 8y agoNo, -v will return 0 unless every line matches: $ cat > foo here's some random text $ grep -v some foo; echo $? here's random text 0 $ grep -v bar foo; echo $? here's some random text 0 $ grep -vE "(here's|some|random|text)" foo; echo $? 1
- mangamadaiyan 8y agoWould grep -c work for your use-case?
- Pete_D 8y agoHow about "awk /pattern/"?