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。
例如:
if grep -q “username” home.txt
then
对username进行处理
else
处理
fi
参考博文:https://blog.csdn.net/sukhoi27smk/article/details/43372979