您的位置:首页 > 运维架构 > Shell

grep -q用于if逻辑判断

2015-10-08 13:49 459 查看
grep -q用于if逻辑判断

 

突然发现grep -q 用于if 逻辑判断很好用。

 

-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。

 
小应用

# cat a.txt

nihao 

nihaooo

hello

   

if  grep -q hello a.txt ; then echo yes;else echo no; fi 

# yes

if grep -q word a.txt; then echo yes; else echo no; fi

#no 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux shell