【改】shell 判断文件中有无特定子串方法(grep)

转自:https://blog.csdn.net/zhuguiqin1/article/details/79160923html

利用grep执行的命令结束代码$?的值来判断是否已经grep到特定的值。post

当$?等于0时,表示已经找到。ui

当$?不等于1时,表示没有找到。spa

当$?大于1时,表示命令执行错误,多是参数错误什么的致使命令没有成功执行。.net

示例代码:code

grep  "abc" aa.txt
if [ $? -ne 0 ] ;then
    echo "grep return a none-zero value, not find abc"
else
    echo "grep return zero value, find abc"
fi
相关文章
相关标签/搜索