GNU bug report logs - #54035
Patch for easier use in scripting pipelines

Previous Next

Package: grep;

Reported by: Ulrich Eckhardt <ulrich.eckhardt <at> base-42.de>

Date: Thu, 17 Feb 2022 07:58:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Ulrich Eckhardt <ulrich.eckhardt <at> base-42.de>
Cc: 54035 <at> debbugs.gnu.org
Subject: bug#54035: Patch for easier use in scripting pipelines
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'.




This bug report was last modified 3 years and 147 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.