On Thu, Feb 17, 2022 at 8:01 AM Ulrich Eckhardt <ulrich.eckha...@base-42.de> wrote: > > I've implemented a `-p` flag for grep, which disables a behaviour that > the exit status is used (abused?) to signal whether any match > occurred.
The behaviour is POSIX. > Now, for an example where it makes a difference. Consider a Bash script > like this: > > # enable automatic error handling > set -eo pipefail > # check for string "issues" in a logfile > cat logfile | grep issue | sort --unique > > If there are no issues in the logs, grep return exit code 1 and the > shell interprets this as an error and exits itself. > Why do we need to implement a workaround in grep while you can do this in shell to ignore the exit code of grep? { grep issue <logfile || :; } | sort --unique > I've implemented that feature here, though it lacks tests yet: > https://github.com/UlrichEckhardt/busybox/tree/grep-pipe-option > Also, I'm currently trying to get the same feature into GNU grep as > well, the long form `--pipe` is used there. I've also considered > `--filter` (because it only filters) as alternative. I'm not fully > happy with either one, maybe someone here comes up with a better > suggestion. I don't see the '--pipe' option in GNU grep manual <https://www.gnu.org/software/grep/manual/grep.html> and I don't think it would be needed considering that you can tell the shell to ignore an exit code already. _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox