我正在尝试编写一个脚本,如果文件中没有特定的字符串,该脚本会执行某些操作。
我知道,为了检查字符串是否可用,我们可以执行以下操作:
if grep -qi "sms" $FILE; then
但是,如何将!
运算符与shell命令结合在一起?
只需将其添加到您的条件之前即可进行相反的评估:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句