码迷,mamicode.com
首页 > 系统相关 > 详细

9-Linux grep return code

时间:2020-06-24 16:28:13      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:uil   ring   tput   like   comm   ror   append   class   selected   

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

9-Linux grep return code

标签:uil   ring   tput   like   comm   ror   append   class   selected   

原文地址:https://www.cnblogs.com/robinunix/p/13187658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!