[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Additional "grep" parameter to change the exit code from 1 to 0, eve
From: |
Jim Meyering |
Subject: |
Re: Additional "grep" parameter to change the exit code from 1 to 0, even if grep doesn't find pattern |
Date: |
Fri, 02 Sep 2011 15:21:28 +0200 |
Robert wrote:
> Hello everybody,
>
> I want to suggest my idea about a additional "grep" parameter which
> would change the exit code 1 to 0, even when "grep" doesn't find a
> pattern. I.e. something similar to "-0".
Thanks, but you can avoid triggering your trap
by appending "|| :" to your grep command.
E.g.,
grep not-found /dev/null || :
Then, even when grep fails, the shell sees only the successful
exit code from the ":" (always succeeding) built-in command.
> In bash programming I often use the "trap" command with the "ERR"
> parameter. "ERR" reacts when a normal command like "grep", "mount", etc.
> produces an non-zero exit code. "ERR" is similar to the bash "set -e" or
> "set -o errexit" option.
>
> My thought is, that NOT finding a pattern, is not always a reason to
> consider the result as an error or the command being unsuccessfully. In
> my opinion, it would just be a handy way to avoid using "awk" or "sed",
> which produce exit code 0, when NOT finding a pattern.
>
> Just an idea... :)
>
> Kind regards,
>
> Robert S.