[BusyBox] grep -qv X bug

David Douthitt ssrat at mailbag.com
Thu Jan 4 14:37:39 UTC 2001


In brief, GNU grep -qv is always quiet; busybox grep -qv echos the 
input when the match fails.  That is, grep -q is ignored when -v is 
used.

Under Red Hat 6.2, I see this behavior:

# uname -a
Linux backadm.cuna.com 2.2.16-3 #1 Mon Jun 19 18:49:25 EDT 2000 i586 
unknown
# grep -V
grep (GNU grep) 2.4

Copyright (C) 1988, 1992-1998, 1999 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.

# cat /etc/*release
Red Hat Linux release 6.2 (Zoot)
# echo FOO | grep -qv F
# echo $?
1
# echo FOO | grep -qv X
# echo $?
0
#

With busybox in Oxygen (an LRP derivative) I see this:

sysadm:/ # uname -a
Linux sysadm 2.2.18 #3 Fri Dec 15 15:46:52 CST 2000 i586 unknown
sysadm:/ # busybox
BusyBox v0.48pre (2000.11.16-01:54+0000) multi-call binary -- GPL2

Usage: busybox [function] [arguments]...
   or: [function] [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use, and 
BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        busybox, cat, chgrp, chmod, chown, clear, cp, cut, date, dd, 
df,
        dmesg, du, dutmp, false, fdflush, find, grep, gunzip, gzip, 
head,
        hostname, id, insmod, kill, killall, ln, loadkmap, logger, ls,
        makedevs, md5sum, mkdir, mkfs.minix, mknod, mktemp, more, 
mount,
        mv, nslookup, ping, printf, rdate, renice, rm, rmdir, rmmod, 
sort,
        swapoff, swapon, sync, tail, tar, tee, touch, tr, true, 
umount,
        uname, uniq, update, uptime, usleep, wc, which, whoami, xargs,
        zcat

sysadm:/ # echo FOO | grep -qv F
sysadm:/ # echo $?
1
sysadm:/ # echo FOO | grep -qv X
FOO
sysadm:/ # echo $?
0
sysadm:/ #

This patch seems to do the trick:

--- grep.c.orig Thu Dec  7 13:56:48 2000
+++ grep.c      Thu Jan  4 03:37:10 2001
@@ -85,6 +85,11 @@

                }
                else if (ret == REG_NOMATCH && invert_search) {
+                       if (be_quiet) {
+                               regfree(&regex);
+                               exit(0);
+                       }
+
                        nmatches++;
                        print_matched_line(line, linenum);
                }


-- 
David Douthitt
UNIX Systems Administrator
HP-UX, Linux, Unixware
ddouthitt at mennonite.minister.net





More information about the busybox mailing list