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

From: Paul Eggert <[email-masked]>
Date: Sat, 19 Feb 2022 08:01:20 -0800

On 2/18/22 00:27, Ulrich Eckhardt wrote:

>   - Shell scripting uses nonzero exit codes to signal errors by default.
>     grep is an exception here (as are cmp, diff and sort as I understand
>     you),

I'm sure there are other exceptions. And there's a long tradition for 
these exceptions. It doesn't sound realistic to upend this longstanding 
practice, or to add options to every such program.

>   - Also, just arguing in the context of grep, there is an option to
>     "just tell me if there was a match, don't give me the results"

That's for efficiency; grep can be waaay faster with -q. There is no 
efficiency argument for the changes you're proposing.

>> 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.
> 
> It doesn't do that here, I wonder why you are seeing an error there?

Possibly you're using a GNU/Linux variant where the dictionary is 
located elsewhere? Or you have something in your .profile? I'm running 
Ubuntu 21.10 x86-64, and if I run this shell command:

bash --norc --noprofile -c 'set -eo pipefail; cat 
/usr/share/dict/american-english | grep -l "^"; echo done'

the output is:

(standard input)

which means that Bash exited without doing the 'echo done'.

> Also, if it did, that would signal an actual error, which is behaviour
> I'm completely fine with.

There is no actual error, in that the "cat ... | grep ..." command does 
just what I wanted it to: grep reported that standard input contained a 
match (which it did). This may help to explain my previous remark that 
scripts that use "set -eo pipefail" need to be verrrry careful.