-q 参数,本意是 Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. 中文意思为,安静模式,不打印任何标准输出。如果有匹配的内容则立即返回状态值0。
[root@node02:/home/test]$ cat 111.txt
hello
[root@node02:/home/test]$ cat check.sh
#!/bin/sh
grep -q "hello" 111.txt
if [[ $? == 0 ]];then
echo "hello in 111.txt"
else
echo "hello does not in 111.txt"
fi
grep -q "hello1" 111.txt
if [[ $? == 0 ]];then
echo "hello1 in 111.txt"
else
echo "hello1 does not in 111.txt"
fi
[root@node02:/home/test]$ sh check.sh
hello in 111.txt
hello1 does not in 111.txt
版权声明:本文为博主原创文章,未经博主允许不得转载。
shell
- 上一篇:Oracle查看缓冲池命中率
- 下一篇:Centos 7 安装蓝鲸CMDB