Subject: Re: bug#54035: Patch for easier use in scripting pipelines

From: Paul Eggert <[email-masked]>
Date: Thu, 17 Feb 2022 19:05:45 -0800

On 2/16/22 23:57, Ulrich Eckhardt wrote:
> In order to fix that bug in the above script, you currently have to
> replace `grep ...` with `grep ... || [ $? = 1 ]`, which is not really
> readable.

Actually, appending something "|| test $? -eq 1" looks readable to me; 
plus, it already works and is portable to non-GNU systems which is a 
plus. Furthermore, it also works with other programs that also return 
0,1,>1 depending on success,failure,error (e.g., 'cmp', 'diff', 'sort'), 
and it doesn't sound like much of a win to add unportable --pipe options 
to every such program.

And it's not just commands like 'cmp' and 'grep'. The following causes 
Bash to exit on GNU/Linux:

set -eo pipefail
cat /usr/share/dict/american-english | grep -l '^'

This is not because of anything 'grep' does, as 'grep' exits with status 
zero. It's because 'cat' exits with nonzero status. Surely we shouldn't 
add a --pipe option to 'cat' too.

Scripts that use "set -eo pipefail" need to be verrrry careful 
regardless of what we do with 'grep'; and if they are careful it won't 
help much to add a --pipe option to 'grep'.