On Thu, 17 Feb 2022 08:32:06 +0800 Kang-Che Sung <explore...@gmail.com> wrote: > On Thu, Feb 17, 2022 at 8:01 AM Ulrich Eckhardt > <ulrich.eckha...@base-42.de> wrote: > > 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
`grep -p ...` rather replaces `grep ... || test $? = 1`. The advantage is that it is explicit about what it does. Understanding the intent of `-p` or `--pipe` is easier than understanding the alternative. > > 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> Misunderstanding: It's not in there! I have it implemented already and I'm trying to get it incorporated there, which takes time due to FSF paperwork. Cheers! Uli _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox