zoukankan      html  css  js  c++  java
  • Linux grep return code

    The exit code is 1 because nothing was matched by grep.

    EXIT STATUS The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2. (Note: POSIX error handling code should check for '2' or greater.)

    The output is zero because the count of 'Total' is zero. This due to the -c option:

    -c, --count Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines. (-c is specified by POSIX.)

    If you would like to force an exit code of 0, you can just append || true to your command:

    echo 'Total' | grep -c No || true
  • 相关阅读:
    Thrift在微服务中的使用
    MySQL 必知必会
    IDEA 内使用 git
    分布式锁
    LeetCode 图
    LeetCode 位运算
    LeetCode 数组
    LeetCode 字符串
    LeetCode 哈希表
    LeetCode 栈和队列
  • 原文地址:https://www.cnblogs.com/kakaisgood/p/11093234.html
Copyright © 2011-2022 走看看