How can I reduce the following bash script?
grep -P \"STATUS: (?!Perfect)\" recess.txt && exit 1
exit 0
It seems like I should be able
I came across this, needing an onlyif
statement for Puppet. As such, Tgr's bash solution wouldn't work, and I didn't want to expand the complexity as in Christopher Neylan's answer.
I ended up using a version inspired by Henri Schomäcker's answer, but notably simplified:
grep -P "STATUS: (?!Perfect)" recess.txt; test $? -eq 1
Which very simply inverts the exit code, returning success only if the text is not found:
test 0 -eq 1
will return 1.test 1 -eq 1
will return 0.test 2 -eq 1
will return 1.Which is exactly what I wanted: return 0 if no match is found, and 1 otherwise.