GNU bug report logs -
#54035
Patch for easier use in scripting pipelines
Previous Next
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Greetings!
The attached patch add a `--pipe` option to grep. When used, grep
only exits with with nonzero status on error. In particular, it
doesn't signal "match" / "no match" through the exit code.
Here's an example using Bash:
# enable automatic error handling
set -eo pipefail
# grep for issues in a logfile to produce a report
cat logfile | grep issue | sort --unique
If grep doesn't find "issue" in its input (which is not an error,
obviously), it exits with status 1. Bash interprets this nonzero exit
code as an error and terminates with an error itself.
In order to fix that bug in the above script, you currently have to
replace `grep ...` with `grep ... || [ $? = 1 ]`, which is not really
readable. As alternative, I've implemented a `--pipe` option, which
only returns nonzero on actual errors, but not when there is no match.
This is a bit of a complementary option to `--quiet`.
Open tasks here:
* FSF paperwork is not finished, so obviously the patch can't be
applied yet.
* Should I add a `-p` to complement the long `--pipe`?
* Should I call it `--pipe` at all? The other alternative I came up
with was `--filter`. I don't really like either of them very much.
Cheers!
Uli
[gnu-grep-pipe-option.patch (text/x-patch, attachment)]
This bug report was last modified 3 years and 147 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.