bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54035: Patch for easier use in scripting pipelines


From: Paul Eggert
Subject: bug#54035: Patch for easier use in scripting pipelines
Date: Thu, 17 Feb 2022 19:05:45 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

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'.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]