Hi! I'm working on a script around grep(1) which calls
set -Eeuo pipefail;
trap 'exit 2;' ERR;
...
| xargs grep regex;
I'd like to be able to return 2 on any errors, like grep(1) does, which
is why I'm using the trap(1). However, I need to workaround the fact
that grep(1) returns non-zero for no matches. What I'm doing at the
moment is
...
| {
xargs grep regex || true;
};
However, this also hides errors from xargs, which I'd like to keep.
Alternatively, I could use something like
...
| while read -r f; do
grep regex "$f" || true;
done;
However, the performance would drop to unusable levels (I experienced
a slow down of 100x in a quick test I did), so it's not an option.
Would you mind adding an option to coerce grep(1) to return 0 on zero
matches?
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
signature.asc
Description: PGP signature
