检查命令的输出是否包含shell脚本中的某个字符串 [英] Checking if output of a command contains a certain string in a shell script
本文介绍了检查命令的输出是否包含shell脚本中的某个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个shell脚本,并试图检查命令的输出是否包含某个字符串。我想我可能不得不使用grep,但我不知道如何。有人知道吗?
I'm writing a shell script, and I'm trying to check if the output of a command contains a certain string. I'm thinking I probably have to use grep, but I'm not sure how. Does anyone know?
推荐答案
测试grep的返回值:
Test the return value of grep:
./somecommand | grep 'string' &> /dev/null
if [ $? == 0 ]; then
echo "matched"
fi
这篇关于检查命令的输出是否包含shell脚本中的某个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文