From owner-freebsd-bugs@FreeBSD.ORG Mon Apr 16 21:40:04 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E71EE1065675 for ; Mon, 16 Apr 2012 21:40:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B8B0E8FC1C for ; Mon, 16 Apr 2012 21:40:04 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3GLe4Jh032718 for ; Mon, 16 Apr 2012 21:40:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q3GLe4Ec032717; Mon, 16 Apr 2012 21:40:04 GMT (envelope-from gnats) Resent-Date: Mon, 16 Apr 2012 21:40:04 GMT Resent-Message-Id: <201204162140.q3GLe4Ec032717@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, David Wolfskill Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D474F106566B for ; Mon, 16 Apr 2012 21:31:41 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from albert.catwhisker.org (m209-73.dsl.rawbw.com [198.144.209.73]) by mx1.freebsd.org (Postfix) with ESMTP id 955148FC12 for ; Mon, 16 Apr 2012 21:31:41 +0000 (UTC) Received: from albert.catwhisker.org (localhost [127.0.0.1]) by albert.catwhisker.org (8.14.5/8.14.5) with ESMTP id q3GLVZTs012469 for ; Mon, 16 Apr 2012 14:31:35 -0700 (PDT) (envelope-from david@albert.catwhisker.org) Received: (from david@localhost) by albert.catwhisker.org (8.14.5/8.14.5/Submit) id q3GLVZ8Z012468; Mon, 16 Apr 2012 14:31:35 -0700 (PDT) (envelope-from david) Message-Id: <201204162131.q3GLVZ8Z012468@albert.catwhisker.org> Date: Mon, 16 Apr 2012 14:31:35 -0700 (PDT) From: David Wolfskill To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: gnu/167009: GNU grep -q can exit !0 even if strings found X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: David Wolfskill List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2012 21:40:05 -0000 >Number: 167009 >Category: gnu >Synopsis: GNU grep -q can exit !0 even if strings found >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 16 21:40:04 UTC 2012 >Closed-Date: >Last-Modified: >Originator: David Wolfskill >Release: FreeBSD 8.3-PRERELEASE i386 >Organization: Wolfskill & Dowling Residence >Environment: System: FreeBSD albert.catwhisker.org 8.3-PRERELEASE FreeBSD 8.3-PRERELEASE #486 234278M: Sat Apr 14 04:01:03 PDT 2012 root@freebeast.catwhisker.org:/common/S1/obj/usr/src/sys/ALBERT i386 >Description: The -q flag for GNU grep is described as: `-q' `--quiet' `--silent' Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the `-s' or `--no-messages' option. `-s' `--no-messages' Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU `grep', traditional `grep' did not conform to POSIX.2, because traditional `grep' lacked a `-q' option and its `-s' option behaved like GNU `grep''s `-q' option. Shell scripts intended to be portable to traditional `grep' should avoid both `-q' and `-s' and should redirect output to `/dev/null' instead. Despite this, there are cases where the use of "grep" to find a string will succeed (with an exit status of 0), while an otherwise-identical search using "grep -q" will merely exit with a non-zero status code. While it's possible that I'm confused, that seems to contradict the above info excerpt. It's also possible that there's something peculiar about the FreeBSD environment (from the perspective of the GNU folks). >How-To-Repeat: I encountered this in looking for certain pathnames in executables, thus: albert(8.3-P)[1] which grep /usr/bin/grep albert(8.3-P)[2] grep --version 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. albert(8.3-P)[3] grep -alw /usr/local /usr/local/bin/bison; echo $? /usr/local/bin/bison 0 albert(8.3-P)[4] strings -a /usr/local/bin/bison | grep -w /usr/local; echo $? /usr/local/lib /usr/local/share/locale /usr/local/share/bison /usr/local/bin/gm4 /usr/local/lib 0 albert(8.3-P)[5] strings -a /usr/local/bin/bison | grep -qw /usr/local ; echo $? 141 albert(8.3-P)[6] Most of the folks to whom I've shown this have agreed that 0 != 141. :-} >Fix: >Release-Note: >Audit-Trail: >Unformatted: