bsd-grep-20080725_1 -v flag busted...

Daniel Roethlisberger daniel at roe.ch
Mon Aug 4 20:29:45 UTC 2008


Gábor Kövesdán <gabor at FreeBSD.org> 2008-08-04:
> Chuck Swiger escribió:
> >I'd just updated the BSD grep port to bsd-grep-20080725_1, but 
> >regrettably have noticed that many things using grep stopped working.  
> >For example, running GNU-style ./configure hangs here:
> >
> >  configure: creating ./config.status
> >  load: 1.15  cmd: sh 72964 [runnable] 7.60u 95.78s 14% 2260k
> >
> >A trivial test case:
> >
> >% echo 'fee\nfi\nfoe\nfum' | ./grep -v fi
> >% echo 'fee\nfi\nfoe\nfum' | /usr/bin/grep -v fi
> >fee
> >foe
> >fum
> >% ./grep --version
> >grep (BSD grep) 2.5.1-FreeBSD
> Hello Chuck,
> 
> thanks for your notes. It seems very strange to me, because GNU grep 
> produces the same output for me. Apart from this, the -v flag was really 
> broken, but I applied some fixes before updating the port and in the 
> version, which I committer, I thought that the -v flag was compatible.
> 
> Here is what I get at the moment:
> 
> > echo 'fee\nfi\nfoe\nfum' | ./grep -v fi
> > echo 'fee\nfi\nfoe\nfum' | /usr/bin/grep -v fi
> > /usr/bin/grep -V
> grep (GNU grep) 2.5.1-FreeBSD
> 
> Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> 
> It's still the same, thus I don't understand how you could produce that 
> output with GNU grep.

I may be stating the obvious, but note that depending on your shell and
it's configuration, echo might not translate \n to an actual newline.
You might need to use `echo -e' instead of `echo' to get four lines
printed instead of one.  /bin/sh and bash need it, ksh doesn't, not sure
about (t)csh.  Also note that our /bin/echo doesn't know about -e and
will never translate \n to a newline.  The following should be more
portable across different shells:

printf 'fee\nfi\nfoe\nfum' | ./grep -v fi
printf 'fee\nfi\nfoe\nfum' | /usr/bin/grep -v fi

-- 
Daniel Roethlisberger
http://daniel.roe.ch/


More information about the freebsd-ports mailing list