grep -q用于if逻辑判断

来源:互联网 发布:mac sierra是什么 编辑:程序博客网 时间:2024/05/17 22:02

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



转 : http://www.th7.cn/system/lin/201307/41741.shtml

0 0
原创粉丝点击