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

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

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

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

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

示例代码:

grep  "abc" aa.txt
if [ $? -ne ] ;then
echo "grep return a none-zero value, not find abc"
else
echo "grep return zero value, find abc"
fi

【改】shell 判断文件中有无特定子串方法(grep)的更多相关文章

  1. 读取同一文件夹下多个txt文件中的特定内容并做统计

    读取同一文件夹下多个txt文件中的特定内容并做统计 有网友在问,C#读取同一文件夹下多个txt文件中的特定内容,并把各个文本的数据做统计. 昨晚Insus.NET抽上些少时间,来实现此问题,加强自身的 ...

  2. shell判断文件类型和权限

    shell  判断文件类型. -d 文件 判断该文件是否存在,并且是否为目录(是目录为真) -e文件 判断该文件是否存在(存在为真) -f文件 判断该文件是否存在,并且是否为文件(是普通文件为真) - ...

  3. shell判断文件是否存在

    转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...

  4. Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  5. shell 判断文件、目录是否存在

    shell判断文件是否存在   1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...

  6. Shell 判断文件或文件夹是否存在

    #shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...

  7. [转] Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  8. shell判断文件夹是否存在

    #shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...

  9. shell判断文件是否存在[转]

    原文出处: http://canofy.iteye.com/blog/252289 shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/htt ...

随机推荐

  1. python3下multiprocessing、threading和gevent性能对比----暨进程池、线程池和协程池性能对比

    python3下multiprocessing.threading和gevent性能对比----暨进程池.线程池和协程池性能对比   标签: python3 / 线程池 / multiprocessi ...

  2. dp培训完结(8.9)

    概率与期望dp 期望: 为什么下面的式子成立? 若x可以取1,2,3,则x+c可以取1+c,2+c,3+c..........x*c可以取1*c,2*c,3*c why? 举个例子(E(x+y)=E( ...

  3. VS Project Property Manage

    概念:Project Property 和 Property Sheet. Project Property:项目属性,是你当前项目的属性配制,保存在你工程的配制文件中,rojectName.vcxp ...

  4. java.lang.NoClassDefFoundError: com/opensymphony/xwork2/util/finder/DefaultClassFinder$InfoBuildingV 解决方法

    问题:严重: Unable to read class [com.spml.action.AddUserAction]java.lang.NoClassDefFoundError: com/opens ...

  5. python接口自动化:对外接口sign签名

    签名参数sign生成的方法: 在接口开发过程中,一般通过时间戳+sign作为密匙加密传输 实现代码如下: #python实现sign签名 import hashlib,time class sign: ...

  6. Windows操作系统命令整理-Win7

    注册表(Windows95以后Windows系统版本,windows server中regedit和regedit32合并为一个新的编辑器,名称仍然是regedit) HKEY_LOCAL_MACHI ...

  7. 20191003 尚硅谷Spring Cloud教学视频

    视频信息 视频日期:2018-4-19 讲师:尚硅谷周阳 Spring Cloud版本:Dalston.RELEASE 当前版本:Greenwich SR3 微服务.微服务架构.Spring Clou ...

  8. 浅谈WebService开发(一)转

    一.什么是WebService: 简单通俗来说,就是企业之间.网站之间通过Internet来访问并使用在线服务,一些数据,由于安全性问题,不能提供数据库给其他单位使用,这时候可以使   用WebSer ...

  9. linux文件io与标准io

    文件IO实际是API,Linux对文件操作主要流程为:打开(open),操作(write.read.lseek),关闭(close). 1.打开文件函数open(): 涉及的头文件:  #includ ...

  10. [Python3] 017 字典的内置方法

    目录 1. Python3 中如何查看 dict() 的内置方法 2. 少废话,上例子 (1) 清理大师 clear() (2) 拷贝君 copy() (3) get(key, default=Non ...