On 6/25/25 13:14, Paul Eggert wrote:
On 2025-06-24 22:28, Thomas Güttler Mailinglisten wrote:
During the last months I wrote
a lot of Bash code, and often I needed to handle the non-zero exit
code of
grep.
It would be handy to have an option to make grep always return zero
(except
"file not found" or similar errors).
I dunno, there are several commands like grep that return exit status
1/2 for different kinds of "failure". ("diff", for example.) I doubt
whether we want to add such an option to all these commands.
"grep GREPARGS || test $? = 1" is short and easy to remember and has
worked everywhere for decades. If you dislike its syntax you can package
it inside a shell function.
I am at great risk of falling into a bike shed[1] here. If grep
works fine and all is happy then we get a zero return value. All
other possible situations *should* return a non-zero error status
that helps silly old UNIX people like me.
If someone needs to write if-then-else-what? clause stuff in code
then that is correct behavior. Why fix that which works fine?
--
--
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
[1] https://en.wikipedia.org/wiki/Law_of_triviality