标签:
-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。
经常碰到要判断某个字符串变量是否包含另外一个字符串的问题,使用grep判断,我们其实只想要返回值,不想有任何输出,这时用-q可解决该问题。
a="aa bb cc dd" echo $a | grep "aa"
if [ $? -eq 0 ]; then
echo "This string is include aa."
else
echo "This string is not include aa."
fi
标签:
原文地址:http://www.cnblogs.com/ManMonth/p/4329135.html