GNU bug report logs -
#57604
[ef]grep usage -> POSIXLY_CORRECT?
Previous Next
Full log
View this message in rfc822 format
Hi Karl,
Sorry to cause you grief, but...
On Wed, Sep 7, 2022 at 7:49 PM Karl Berry <karl <at> freefriends.org> wrote:
>
> [ef]grep
>
> I guess my basic issue is that I don't understand the benefit of the new
> warning. It causes a lot of trouble. What is the countervailing
> positive benefit?
Some must care about portability, and these warnings help them do a better job.
As Gary mentioned above, it's easy to disable them.
> $ grep '\Q' /dev/null
> grep: warning: stray \ before Q
> It would be nice to be able to turn those off too. (It hit me today.)
I would argue that it is even more important to retain these
stray-backslash warnings, because they tend to highlight real bugs.
Consider these uses of \d:
$ echo d | grep-3.7 '\d'
d
$ echo d | grep-3.8 '\d'
grep: warning: stray \ before d
Anyone used to PCRE regexps (who isn't, these days) knows that its
"\d" is intended to match a digit, not the letter "d". With grep-3.7,
you'd get misbehavior and no warning about your error. With grep-3.8,
you'll get the diagnostic and maybe switch to using "grep -P", where
"\d" works as expected -- switching from \d to [0-9] hurts readability
and feels like dumbing-down, especially when there are two or more \d
uses. Using PCRE's \Q...\E groups *without -P* is another issue that
is now diagnosed.
For example, the following upstream projects have misuses of grep that
are exposed by running this:
git grep 'grep .*\\[dQE]' | grep -ve '-[[:alnum:]]*P'
- linux
scripts/checkpatch.pl: `grep -Eq
"\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
- gcc
libgo/go/cmd/go/testdata/script/mod_get_lazy_indirect.txt:grep
'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod
libgo/go/cmd/go/testdata/script/mod_get_lazy_indirect.txt:! grep
'rsc.io/quote v\d+\.\d+\.\d+$' go.mod
libgo/go/cmd/go/testdata/script/mod_get_lazy_indirect.txt:grep
'rsc.io/quote v\d+\.\d+\.\d+$' go.mod
libgo/go/cmd/go/testdata/script/mod_get_lazy_indirect.txt:! grep
'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod
This bug report was last modified 1 year and 298 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.