On 2021/01/26 11:18, Jordan Geoghegan wrote:
> 
> 
> On 1/26/21 5:47 AM, Stuart Henderson wrote:
> > On 2021/01/25 00:53, Sebastian Benoit wrote:
> >> Sebastian Benoit(be...@openbsd.org) on 2021.01.25 00:27:05 +0100:
> >>> Theo de Raadt(dera...@openbsd.org) on 2021.01.24 16:01:32 -0700:
> >>>> Stuart Henderson <s...@spacehopper.org> wrote:
> >>>>
> >>>>> On 2021/01/24 12:10, Theo de Raadt wrote:
> >>>>>> I completely despise that the option is called "--null".
> >>>>>>
> >>>>>> Someone was a complete idiot.
> >>>>> gnu grep has both --null and -z for this (why do they do that?!).
> >>>>> If it's added as --null it should be added as -z too.
> >>>>>
> >>>>> Looking at Debian codesearch most things using it as --null use other
> >>>>> long options that we don't have. Maybe just adding as -z would be
> >>>>> enough. It does seem a useful and fairly widely supported feature.
> >>>> Yes, maybe just add -z.
> >>> Actually it's "-Z, --null". The lowercase -z in gnu grep is
> >>>
> >>>        -z, --null-data
> >>>               Treat input and output data as sequences of lines, each
> >>>         terminated by a zero byte (the ASCII NUL character) instead of
> >>>         a newline.  Like the -Z or --null option, this option can be
> >>>         used with commands like sort-z to process arbitrary file
> >>>         names.
> >> And we already have -z for "force grep to behave as zgrep".
> > sigh.. OK I guess we are better skipping the short flag and just use --null
> >
> >> Diff below with tedu@ suggestion and changed manpage text.
> > ok with me. if I was committing I would whine about the stupid flag in
> > commit log ;)
> >
> > [snip]
> 
> Why is a short flag not being included? '-z' and '-0' are both available in 
> our grep.

So after sorting out the caps mixups in the quoted text above:

ggrep:  -z      --null-data
        -Z      --null
grep:   -Z      zgrep mode

i.e. the flag which is used by other implementations for the same feature is
already used in our grep for a different non-standard feature. Using a short
flag for a related but different feature is even worse.

-0 would the obvious "nice" option but now I see why ggrep didn't use
it for the feature: it's not actually available. It currently specifies
"print 0 lines of context". That's the same as plain grep with ours, but
with ggrep it prints -- denoting skipped lines:

$ printf ' 1\n 2\n 2\n 1\n 2\n 1\n' | ggrep -0 2
 2
 2
--
 2

While it doesn't seem entirely sensible that someone should rely on
that, it does currently "work" (I could almost understand someone setting
a variable for lines of context, setting it to 0 to disable context, and
using "| grep -$whatever"). And dumping NULs into some processing
pipeline that isn't prepared for them is also not sensible.

Moral of the story: don't rely on extensions to standard tools, write
your shell scripts in perl instead!

Reply via email to