I'm trying to write a script which does something if a particular string is not present in a file.
I know that in order to check if string is available, we can do something like:
if grep -qi "sms" $FILE; then
But how do I combine a ! operator with a shell command?
Just add it in front of your condition to make it evaluate on the contrary:
if ! grep -qi "sms" $FILE; then echo "yes"; fi
^
$ cat a
hello
bye
$ if ! grep -qi "sms" a; then echo "sms not found"; fi
sms not found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With