From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 15 18:23:52 2017 Received: (at submit) by debbugs.gnu.org; 15 Aug 2017 22:23:52 +0000 Received: from localhost ([127.0.0.1]:39975 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhkFc-0008GA-2Z for submit@debbugs.gnu.org; Tue, 15 Aug 2017 18:23:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46331) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhju2-0005wH-NM for submit@debbugs.gnu.org; Tue, 15 Aug 2017 18:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhjtr-0000jh-SA for submit@debbugs.gnu.org; Tue, 15 Aug 2017 18:01:29 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_20,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:43024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhjtr-0000ix-P0 for submit@debbugs.gnu.org; Tue, 15 Aug 2017 18:01:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhjtn-00018X-O8 for bug-grep@gnu.org; Tue, 15 Aug 2017 18:01:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhjtm-0000eX-S0 for bug-grep@gnu.org; Tue, 15 Aug 2017 18:01:19 -0400 Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]:35176) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dhjtm-0000bd-BJ for bug-grep@gnu.org; Tue, 15 Aug 2017 18:01:18 -0400 Received: by mail-pg0-x22e.google.com with SMTP id v189so13439829pgd.2 for ; Tue, 15 Aug 2017 15:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=google-2016-06-03; h=mime-version:from:date:message-id:subject:to; bh=JM3sbGac3qovvtxPSeNS6dU+tlvkSBY6/Eewbt2u+O8=; b=F1t8kFEQpTGDI9QgCwv73uTlR+RRD+jGCCBX5fu/JWLTVylg/q9s+KZmfcDaf4PNXn TiXdTMNteFhdvbtsZ1bNqZ1+D2U39lWeVzgpYzUrzMebnK2R7bBkftH0vfFEQhbzDADX NjuBpODYzXt99NOGxU+JDThugXicXUQQK6fC9Nqxky6tVTXM5u9idgXcfasEP5tTdhlD UCYMG/VFjr5mr//4N6n1N8zNRrFahkfAEBHkgOhn7uzoxVr2jHQFIbFDnA2NilTffu43 w2DneVBJj5Ks2u0JualgGxmk4Y9gFkVLkQKAFavWxtJ72x6QJTZ1R21llOXFdSpXUk4k 33ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=JM3sbGac3qovvtxPSeNS6dU+tlvkSBY6/Eewbt2u+O8=; b=CJ94QvmNWuUyeDB8v6YQPkpGSU01L2lZHukhQVP2RyzpQasvFtMoqR3XgotF8QUujL 5/yOsmu9WF17V6jguXbY1LQxRBxVdf5c/Z/CJPG/KnvaKDT5Sup3keVZMvBlmTDtFSK1 P4tOP+IIf/USPBH8VJ5az7gDPv82snWVCKYBDGZ0XEASQCkc1Y8xjwT2tFcjUmN+qxeD m06QLoRvVFlBuLX7pZmOJE39B2M2nNmniMTAGYtkfathRmpujX/XBf0v3PQs2UBmj78/ V/IyhzwkVj4MINWjKDeuxE5HeBQf30/5HVz/VeRpLBYk6H3CF7t8IwiGdsWHeuuQB/Wi RBpA== X-Gm-Message-State: AHYfb5hrm6i38cB7yHNb/6ZKA4C/jF3zpkFeitSXuopZAVgdYSmpM083 XcLZ3nR46GsCbbDHGgkjSDE2mvzzrX4Bj2Y= X-Received: by 10.99.60.12 with SMTP id j12mr29671263pga.18.1502834474213; Tue, 15 Aug 2017 15:01:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.132.193 with HTTP; Tue, 15 Aug 2017 15:01:13 -0700 (PDT) From: Anthony Sottile Date: Tue, 15 Aug 2017 15:01:13 -0700 Message-ID: Subject: Inconsistent exit code with --files-without-match To: bug-grep@gnu.org Content-Type: text/plain; charset="UTF-8" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 15 Aug 2017 18:23:50 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) Given the exit code of `grep` vs. `grep -v`, I expect similar results when comparing `grep -l` and `grep -L` (`--files-with-matches` / `--files-without-match`) For at least `grep` / `grep -v` / `grep -l` when the "search" is successful, it exits `0` and when the search is unsuccessful it exits `1`. `grep -L` (`--files-without-match`) does not follow this pattern which I believe to be an oversight / bug. Consider the following: $ echo hello > f # Search is for "hello", it matches so exit code is 0 $ grep hello -- f; echo $? hello 0 # Search is for "hi", it fails to match so the exit code is 1 $ grep hi -- f; echo $? 1 # Search is for not "hi", it matches so exit code is 0 $ grep -v hi -- f; echo $? hello 0 # Search is for not "hello", it fails to match so the exit code is 1 $ grep -v hello -- f; echo $? 1 # Search is for filenames containing hello, it matches so exit code is 0 $ grep -l hello -- f; echo $? f 0 # Search is for filenames containing hi, it fails to match so exit code is 1 $ grep -l hi -- f; echo $? 1 # Search is for filenames not containing hi, this search is successful **but it exits 1** $ grep -L hi -- f; echo $? f 1 # Search is for filenames not containing hello, this search fails **but it exits 0** $ grep -L hello -- f; echo $? 0 Anthony From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 16 01:15:11 2017 Received: (at 28105) by debbugs.gnu.org; 16 Aug 2017 05:15:11 +0000 Received: from localhost ([127.0.0.1]:40132 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhqff-0006QW-9C for submit@debbugs.gnu.org; Wed, 16 Aug 2017 01:15:11 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhqfd-0006QJ-SX for 28105@debbugs.gnu.org; Wed, 16 Aug 2017 01:15:10 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 54A51160869; Tue, 15 Aug 2017 22:15:04 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Ef0c6TDOdBkt; Tue, 15 Aug 2017 22:15:03 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A7F8716086A; Tue, 15 Aug 2017 22:15:03 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id knqvvRN41UtE; Tue, 15 Aug 2017 22:15:03 -0700 (PDT) Received: from [192.168.1.9] (unknown [47.153.184.153]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 89179160869; Tue, 15 Aug 2017 22:15:03 -0700 (PDT) Subject: Re: bug#28105: Inconsistent exit code with --files-without-match To: Anthony Sottile , 28105@debbugs.gnu.org References: From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> Date: Tue, 15 Aug 2017 22:15:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 28105 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Anthony Sottile wrote: > # Search is for filenames not containing hi, this search is successful > **but it exits 1** > $ grep -L hi -- f; echo $? > f > 1 > # Search is for filenames not containing hello, this search fails > **but it exits 0** > $ grep -L hello -- f; echo $? > 0 The grep documentation says exit status depends on whether lines (not files) are selected, so grep is conforming to its documentation here. Perhaps grep's documentation and behavior could be changed, though I worry that existing uses of grep might be adversely affected. What is the use case that justifies such a change? From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 16 18:04:34 2017 Received: (at 28105) by debbugs.gnu.org; 16 Aug 2017 22:04:34 +0000 Received: from localhost ([127.0.0.1]:41634 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1di6QT-0004lY-TH for submit@debbugs.gnu.org; Wed, 16 Aug 2017 18:04:34 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:36184) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1di6QR-0004lK-Iv for 28105@debbugs.gnu.org; Wed, 16 Aug 2017 18:04:33 -0400 Received: by mail-pg0-f51.google.com with SMTP id i12so29505086pgr.3 for <28105@debbugs.gnu.org>; Wed, 16 Aug 2017 15:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=google-2016-06-03; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=tcZ0FnxtZwavDxD6uZMww5oWoO7fXcddDPJPeAVsj7Y=; b=hllRXr6QrTB5tWNN1st13wf13Pn4e38oapQELdPpUKmdR6NyO9WWmsW5hE5vxXLdcp EqjkGwmMszwgGNSbvIqf5uLtg2JEuUIVl/wewAav3kseobq8iqkgw/msLozsCW0tSLwH cvbuYCyrE2sp0OQYI2H33+C85dpO6DvZhnUEGDMhFNLpE/ywfTWnqaeKkBeC91mC1Vhy eEHS1m/4MIgUN/NTdPvq3SY72ItVhj+wFFyjTDAWT+dW5Xonack1HwwdFpaVMdql4ICD Pbd8/82OpGFkJiTtErfeyKi9MlBUVr1753kElgzSZbmqdLcEYEl3Lt0DquZ9jPiuGSwd EuQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=tcZ0FnxtZwavDxD6uZMww5oWoO7fXcddDPJPeAVsj7Y=; b=lAxMs+DTJ/dsXOxloCvBqsj63Y4tnxZdOrOlhDvfuwkJDyeL96M55wWjdipUwZmq8P TTSG4HtnzTT+uZo/f9p/52CUARfZXFXUjkUuBX04UOQhNComohMMG9BsZo9Cb2y5HTSY 26Hg23uBmlh7p/Ge36IJ+gPAl0J/GHQ/bX+BPvsx/sapAI7CInirIqhqVKgz3oyiT1fZ x6TUKbEVg03dXs14Esgc7/Qmn8jWOryqVCSWZEZr0XXm02xWPxYtBjMJkNhNh5VNqH+k UOZuQQ33h3i2eLFzIMDmeZJICr/Oyha1GY7y+UipN4NUanMpzmbATLRceNIERMgclkJV HxGA== X-Gm-Message-State: AHYfb5ioTzoM5TJM8SvIBD4DMzBaQgKJTx+KFtotoKASaD6Dfn8LiaZI kCaTCNCDAUy+NkVnLPn6TT14qdVvScY/ X-Received: by 10.99.23.100 with SMTP id 36mr2992466pgx.118.1502921065643; Wed, 16 Aug 2017 15:04:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.132.193 with HTTP; Wed, 16 Aug 2017 15:04:25 -0700 (PDT) In-Reply-To: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> References: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> From: Anthony Sottile Date: Wed, 16 Aug 2017 15:04:25 -0700 Message-ID: Subject: Re: bug#28105: Inconsistent exit code with --files-without-match To: Paul Eggert Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 28105 Cc: 28105@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) On Tue, Aug 15, 2017 at 10:15 PM, Paul Eggert wrote: > Anthony Sottile wrote: >> >> # Search is for filenames not containing hi, this search is successful >> **but it exits 1** >> $ grep -L hi -- f; echo $? >> f >> 1 >> # Search is for filenames not containing hello, this search fails >> **but it exits 0** >> $ grep -L hello -- f; echo $? >> 0 > > > The grep documentation says exit status depends on whether lines (not files) > are selected, so grep is conforming to its documentation here. Perhaps > grep's documentation and behavior could be changed, though I worry that > existing uses of grep might be adversely affected. What is the use case that > justifies such a change? Admittedly, I'm down a rabbit hole at this point but I'll try and explain the full pathway :) My initial goal is I am writing a tool to manage multiple git repositories: - https://github.com/asottile/all-repos One of the goals of this tool is to be able to grep across all of the repositories, mapping `git grep` over each repository fits this goal pretty well. `all-repos-grep` supports two modes: - normal mode: - for each repository run `git grep $args` - if that `git grep` command returns `0`, reproduce the output with the repository name prefixing each line. - --repos-with-matches: - for each repository run `git grep --quiet $args` - if that `git grep` command returns `0`, include this repository name in the output While trying some queries, I noticed an oddity (with git grep, not with gnu grep) in that `git grep -L ...` and `git grep --quiet -L` were returning different exit codes. I then reported a bug to the git mailing list about this discrepancy between return codes when `--quiet` was passed on the cli. I also submitted a patch to fix this discrepancy. It was at this point that a git maintainer noticed that `git grep -L` and `grep -L` disagreed in exit codes (deferring my patch until the correct way forward on what `git grep`'s exit codes should be). The current `git grep -L` exits 1 when no files fit the search (that is, they *don't* contain the pattern), while `grep -L` exits 0 (the current `git grep -L` behaviour is the one I'm suggesting for `grep -L`). I essentially have two options: - grep documents / adjust behaviour to be more consistent with "return 0 when successfully finding things", `git grep -L` behaves the same as today with exit codes. - adjust my tool to *ignore* exit codes and instead look at output. This would also mean dropping the `--quiet` optimization. My main argument is that the inconsistency between grep with/without `-L` hurts scriptability due to inconsistency. Anthony From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 16 20:04:21 2017 Received: (at 28105) by debbugs.gnu.org; 17 Aug 2017 00:04:21 +0000 Received: from localhost ([127.0.0.1]:41712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1di8IP-0004kn-6E for submit@debbugs.gnu.org; Wed, 16 Aug 2017 20:04:21 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55354) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1di8IO-0004kb-0f for 28105@debbugs.gnu.org; Wed, 16 Aug 2017 20:04:20 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 80863160868; Wed, 16 Aug 2017 17:04:14 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id RiYKK1Ikn06c; Wed, 16 Aug 2017 17:04:13 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D875C160862; Wed, 16 Aug 2017 17:04:13 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9Gk2ccs3M_zY; Wed, 16 Aug 2017 17:04:13 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id B67F2160868; Wed, 16 Aug 2017 17:04:13 -0700 (PDT) Subject: Re: bug#28105: Inconsistent exit code with --files-without-match To: Anthony Sottile References: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Wed, 16 Aug 2017 17:04:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 28105 Cc: 28105@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On 08/16/2017 03:04 PM, Anthony Sottile wrote: > It was at this point that a git maintainer noticed that `git grep -L` > and `grep -L` disagreed in exit codes (deferring my patch until the > correct way forward on what `git grep`'s exit codes should be). > Thanks for the summary. Do you have a URL for the git bug report and maintainer response? That'd be helpful here. You do make a case that the exit status for grep -L should differ from what it is now. From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 17 00:17:56 2017 Received: (at 28105) by debbugs.gnu.org; 17 Aug 2017 04:17:56 +0000 Received: from localhost ([127.0.0.1]:41827 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diCFo-00067X-G0 for submit@debbugs.gnu.org; Thu, 17 Aug 2017 00:17:56 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:37315) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diCFm-00067I-G9 for 28105@debbugs.gnu.org; Thu, 17 Aug 2017 00:17:55 -0400 Received: by mail-pg0-f48.google.com with SMTP id y129so34361150pgy.4 for <28105@debbugs.gnu.org>; Wed, 16 Aug 2017 21:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=google-2016-06-03; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=S95BT06SaEDFcmdlbB1Wn05LzlAnTEOTId2uKao0dr0=; b=luoIDgCC6GYO0hmktPgY0K96GB0Q/8fOBPf6pBfkhbFKNMxt72129DuP4+cQx5QiDI rJhaoZBV04i4JmfdrMoQ2P9dn7x7wdB9wjZNMjdcIhSvwTNsmjlSn6Fo6EHEM/jXlH9G kAa/Qc6iBiOpo2DEUY9Q5quUdNbT1r7/3j7DlX28MffLi47p58jn3R0T7UdZFaBriisf 2AUy8varBjiukYRUhq5GBeIqxT6y/Fny22lLYuZMkdBpW4uQSHkdjEY/p5gyWg6cBPx2 8FnpVZbizlMoeaoPz1CXznTJY9WOqwhz6v0vVOdqXqwDtLwce6kPBMCMqDgm++JvrO3W UPOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=S95BT06SaEDFcmdlbB1Wn05LzlAnTEOTId2uKao0dr0=; b=RQGpr4otdN2bra+8Odl2JDxja0jR4xUVTimN8FqTc8199FgirCXE+Oa9ZgkYSEN/fa aTquLPL1TN5PdAPQmlgdlW4xoaa20i7d8gQ9hB673kqqyQtYUyGSv6t9yiFPiO8rIEpa 8yHrulH5TQuUoZ5QZINrckOeevgaHtVowglup9/W4B11oBJjSH3MTc50U9j+eYRcesd4 ud1UGojq1CHj0yVYFTG25SRtjYnhjMSuW507GH1gqTxIZWFPdNrXe7jdeaCxUT+FyKzo m/S1gfTuKmUZUpjV92vXFvMmIMzvmxeeEYUdR4M4adGp5p4kpVnDCuesVTsv6UyKQhpr O6iw== X-Gm-Message-State: AHYfb5geUt8ryXOTbVgsVu8ylL1/26fcCPylnd0Gr/BhvYZNA7mcKjCK 9RlZDJfWVVjN+Xdc5CTQYLECq0xDWQLF X-Received: by 10.99.131.67 with SMTP id h64mr3678407pge.310.1502943468663; Wed, 16 Aug 2017 21:17:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.132.193 with HTTP; Wed, 16 Aug 2017 21:17:48 -0700 (PDT) In-Reply-To: References: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> From: Anthony Sottile Date: Wed, 16 Aug 2017 21:17:48 -0700 Message-ID: Subject: Re: bug#28105: Inconsistent exit code with --files-without-match To: Paul Eggert Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 28105 Cc: 28105@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Wed, Aug 16, 2017 at 5:04 PM, Paul Eggert wrote: > On 08/16/2017 03:04 PM, Anthony Sottile wrote: >> >> It was at this point that a git maintainer noticed that `git grep -L` >> and `grep -L` disagreed in exit codes (deferring my patch until the >> correct way forward on what `git grep`'s exit codes should be). >> > Thanks for the summary. Do you have a URL for the git bug report and > maintainer response? That'd be helpful here. You do make a case that the > exit status for grep -L should differ from what it is now. > I'm not sure what the "official" mirror of the mailing list is but here's a mirror that I found that works: - Initial bugreport about `--quiet`: http://marc.info/?l=git&m=150281283027760&w=2 - Patch and discussion: http://marc.info/?l=git&m=150283014132406&w=2 From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 17 17:22:08 2017 Received: (at 28105-done) by debbugs.gnu.org; 17 Aug 2017 21:22:08 +0000 Received: from localhost ([127.0.0.1]:43236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diSEy-0002kQ-Cp for submit@debbugs.gnu.org; Thu, 17 Aug 2017 17:22:08 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:38506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diSEw-0002jv-9W for 28105-done@debbugs.gnu.org; Thu, 17 Aug 2017 17:22:06 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 48621160880; Thu, 17 Aug 2017 14:22:00 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id SzNjiwCGPhKM; Thu, 17 Aug 2017 14:21:59 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 56D4F160870; Thu, 17 Aug 2017 14:21:59 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id g3pEc4TK4zvK; Thu, 17 Aug 2017 14:21:59 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 3905B16083B; Thu, 17 Aug 2017 14:21:59 -0700 (PDT) Subject: Re: bug#28105: Inconsistent exit code with --files-without-match To: Anthony Sottile References: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Thu, 17 Aug 2017 14:21:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------A65BC24B94D21D4B953889F5" Content-Language: en-US X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 28105-done Cc: 28105-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) This is a multi-part message in MIME format. --------------A65BC24B94D21D4B953889F5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for the pointer. It looks to me like git-grep's behavior is better than grep's, so I installed the attached. --------------A65BC24B94D21D4B953889F5 Content-Type: text/x-patch; name="0001-grep-L-exits-with-status-0-if-a-file-is-selected.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-grep-L-exits-with-status-0-if-a-file-is-selected.patch" >From 92526f7246464825c5547ceb08e01433e035c867 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 17 Aug 2017 14:15:35 -0700 Subject: [PATCH] grep: -L exits with status 0 if a file is selected Problem reported by Anthony Sottile (Bug#28105). * NEWS, doc/grep.texi (Exit Status), src/grep.c (usage): Document this. * src/grep.c (grepdesc): Implement it. * tests/skip-read: Test it. --- NEWS | 5 +++++ doc/grep.texi | 3 +++ src/grep.c | 6 +++--- tests/skip-read | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 81f51b5..9ed78fb 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,11 @@ GNU grep NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Changes in behavior + + The --files-without-match (-L) option now causes grep to succeed + when a file is listed, instead of when a line is selected. This + resembles what git-grep does. * Noteworthy changes in release 3.1 (2017-07-02) [stable] diff --git a/doc/grep.texi b/doc/grep.texi index 24800c9..865acf1 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -1067,6 +1067,9 @@ and only when @env{POSIXLY_CORRECT} is not set. Normally the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred. However, if the +@option{-L} or @option{--files-without-match} is used, the exit status +is 0 if a file is listed, 1 if no files were listed, and 2 if an error +occurred. Also, if the @option{-q} or @option{--quiet} or @option{--silent} option is used and a line is selected, the exit status is 0 even if an error occurred. Other @command{grep} implementations may exit with status diff --git a/src/grep.c b/src/grep.c index a37e87b..5847c7a 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1863,11 +1863,11 @@ grepdesc (int desc, bool command_line) fflush_errno (); } - status = !count; + status = !count != (list_files == LISTFILES_NONMATCHING); if (list_files == LISTFILES_NONE) finalize_input (desc, &st, ineof); - else if (list_files == (status ? LISTFILES_NONMATCHING : LISTFILES_MATCHING)) + else if (status == 0) { print_filename (); putchar_errno ('\n' & filename_mask); @@ -1994,7 +1994,7 @@ Context control:\n\ printf (_("\ When FILE is '-', read standard input. With no FILE, read '.' if\n\ recursive, '-' otherwise. With fewer than two FILEs, assume -h.\n\ -Exit status is 0 if any line is selected, 1 otherwise;\n\ +Exit status is 0 if any line (or file if -L) is selected, 1 otherwise;\n\ if any error occurs and -q is not given, the exit status is 2.\n")); emit_bug_reporting_address (); } diff --git a/tests/skip-read b/tests/skip-read index 1eef87e..3c32c48 100755 --- a/tests/skip-read +++ b/tests/skip-read @@ -15,7 +15,7 @@ for opts in '-m0 y' '-f /dev/null' '-v ""'; do eval returns_ 1 grep -l $opts $matcher /dev/null > out || fail=1 compare /dev/null out || fail=1 done - eval returns_ 1 grep -L $opts $matcher /dev/null > out || fail=1 + eval grep -L $opts $matcher /dev/null > out || fail=1 compare exp out || fail=1 done done -- 2.13.5 --------------A65BC24B94D21D4B953889F5-- From unknown Tue Jun 24 22:38:59 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 15 Sep 2017 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 06 13:39:57 2020 Received: (at control) by debbugs.gnu.org; 6 Aug 2020 17:39:57 +0000 Received: from localhost ([127.0.0.1]:54879 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k3jrx-0002xX-IX for submit@debbugs.gnu.org; Thu, 06 Aug 2020 13:39:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39658) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k3jrv-0002xF-Ht for control@debbugs.gnu.org; Thu, 06 Aug 2020 13:39:55 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:54465) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3jrq-0003KR-90 for control@debbugs.gnu.org; Thu, 06 Aug 2020 13:39:50 -0400 Received: from 241.red-88-3-77.dynamicip.rima-tde.net ([88.3.77.241]:42429 helo=[192.168.1.2]) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1k3jrp-0002D0-Oh for control@debbugs.gnu.org; Thu, 06 Aug 2020 13:39:50 -0400 Message-ID: <5F2C40B9.3040809@gnu.org> Date: Thu, 06 Aug 2020 19:41:13 +0200 From: Antonio Diaz Diaz User-Agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: unarchive 28105 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) unarchive 28105 From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 07 07:12:46 2020 Received: (at submit) by debbugs.gnu.org; 7 Aug 2020 11:12:46 +0000 Received: from localhost ([127.0.0.1]:55909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k40Io-0002dc-I8 for submit@debbugs.gnu.org; Fri, 07 Aug 2020 07:12:46 -0400 Received: from lists.gnu.org ([209.51.188.17]:33092) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k40Im-0002dU-21 for submit@debbugs.gnu.org; Fri, 07 Aug 2020 07:12:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k40Il-0001An-T1 for bug-grep@gnu.org; Fri, 07 Aug 2020 07:12:43 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:48156) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k40Il-0006uP-Jy for bug-grep@gnu.org; Fri, 07 Aug 2020 07:12:43 -0400 Received: from 241.red-88-3-77.dynamicip.rima-tde.net ([88.3.77.241]:42511 helo=[192.168.1.2]) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1k40Ik-0006gY-Jf for bug-grep@gnu.org; Fri, 07 Aug 2020 07:12:43 -0400 Message-ID: <5F2D377D.5050805@gnu.org> Date: Fri, 07 Aug 2020 13:14:05 +0200 From: Antonio Diaz Diaz User-Agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 MIME-Version: 1.0 To: bug-grep@gnu.org Subject: bug#28105: Inconsistent exit code with --files-without-match References: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> In-Reply-To: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Sorry for being late in the conversation, but I didn't know about this change in grep's exit status until now. On Tue, 15 Aug 2017 22:16:58 -0700 Paul Eggert wrote: > The grep documentation says exit status depends on whether lines (not > files) are selected, so grep is conforming to its documentation here. Conforming to its documentation and to POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html EXIT STATUS The following exit values shall be returned: 0 One or more lines were selected. 1 No lines were selected. >1 An error occurred. Inverting the exit status of 'grep -L' also departs from the exit status one could expect from the etymology of grep itself. (The ed command 'g/RE/p' fails if no lines match). > Perhaps grep's documentation and behavior could be changed, though I > worry that existing uses of grep might be adversely affected. I have recently received a report[1] that the change[2] in exit status of GNU grep when using -L has in fact affected zgrep adversely. [1] http://www.mail-archive.com/zutils-bug@nongnu.org/msg00120.html [2] http://www.mail-archive.com/bug-grep@gnu.org/msg06886.html This change in grep breaks zgrep (from zutils) and gzgrep (from gzip) (and possibly other *zgrep tools) because they both feed the decompressed contents of the file to grep through stdin and must replace the string "(standard input)" printed by grep with the name of the matching file, for which they depend on the exit status of grep which has now been changed. What worries me most is that I have been unable to find a reliable way to make zgrep work with both old and new versions of GNU grep. This change may also be incompatible with other tools like grep-dctrl: http://manpages.debian.org/stretch/dctrl-tools/grep-dctrl.1.en.html#DIAGNOSTICS This change also breaks the internal logic of the -q option. Until GNU grep 3.1 the -q (quiet) option just suppressed the output, but didn't change the exit status in absence of errors. But in GNU grep 3.2 to 3.4 -q inverts the exit status when -L is also used. Now 'grep -L > /dev/null' and 'grep -Lq' return opposite values. Note that the original reporter who requested this change in GNU grep also reported the inconsistency of -Lq to git-grep: http://marc.info/?l=git&m=150281283027760&w=2 Inconsistent exit code for `git grep --files-without-match` with `--quiet` $ ./git-grep --files-without-match nope -- blob.c; echo $? blob.c 0 $ ./git-grep --files-without-match --quiet nope -- blob.c; echo $? 1 I expect both to exit 0 I propose to revert this change to remain consistent with POSIX. If this is not possible or desirable, then I propose to limit the function of -q to quieten standard output but without reversing the exit status of -L, and modify the POSIX standard to reflect this change. Best regards, Antonio. From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 22 17:12:00 2020 Received: (at 28105-done) by debbugs.gnu.org; 22 Aug 2020 21:12:00 +0000 Received: from localhost ([127.0.0.1]:51593 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k9anw-0000CO-EN for submit@debbugs.gnu.org; Sat, 22 Aug 2020 17:12:00 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41976) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k9anr-0000C7-7d for 28105-done@debbugs.gnu.org; Sat, 22 Aug 2020 17:11:58 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A6D9E1600EB; Sat, 22 Aug 2020 14:11:49 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id AbFp_pFCGTOH; Sat, 22 Aug 2020 14:11:48 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 522A31600F1; Sat, 22 Aug 2020 14:11:48 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nru94oLULdbC; Sat, 22 Aug 2020 14:11:48 -0700 (PDT) Received: from [192.168.1.9] (cpe-75-82-69-226.socal.res.rr.com [75.82.69.226]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 21CD71600EB; Sat, 22 Aug 2020 14:11:48 -0700 (PDT) From: Paul Eggert Subject: Re: bug#28105: Inconsistent exit code with --files-without-match To: Antonio Diaz Diaz References: <99399429-e73f-8a87-1a12-9f52b6c1a281@cs.ucla.edu> <5F2D377D.5050805@gnu.org> Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUlOQkV5QWNtUUJFQURB QXlIMnhvVHU3cHBHNUQzYThGTVpFb243NGRDdmM0K3ExWEEySjJ0QnkycHdhVHFmCmhweHhk R0E5Smo1MFVKM1BENGJTVUVnTjh0TFowc2FuNDdsNVhUQUZMaTI0NTZjaVNsNW04c0thSGxH ZHQ5WG0KQUF0bVhxZVpWSVlYL1VGUzk2ZkR6ZjR4aEVtbS95N0xiWUVQUWRVZHh1NDd4QTVL aFRZcDVibHRGM1dZRHoxWQpnZDdneDA3QXV3cDdpdzdlTnZub0RUQWxLQWw4S1lEWnpiRE5D UUdFYnBZM2VmWkl2UGRlSStGV1FONFcra2doCnkrUDZhdTZQcklJaFlyYWV1YTdYRGRiMkxT MWVuM1NzbUUzUWpxZlJxSS9BMnVlOEpNd3N2WGUvV0szOEV6czYKeDc0aVRhcUkzQUZINmls QWhEcXBNbmQvbXNTRVNORnQ3NkRpTzFaS1FNcjlhbVZQa25qZlBtSklTcWRoZ0IxRApsRWR3 MzRzUk9mNlY4bV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rSE5Jb0Y2 Q2pETDJvbXU1Y0VxNFJESE00NFFxUGs2Cmw3TzBwVXZOMW1UNEIrUzFiMDhSS3BxbS9mZjAx NUUzN0hOVi9waUl2Smx4R0FZejhQU2Z1R0NCMXRoTVlxbG0KZ2RoZDkvQmFiR0ZiR0dZSEE2 VTQvVDV6cVUrZjZ4SHkxU3NBUVoxTVNLbEx3ZWtCSVQrNC9jTFJHcUNIam5WMApxNUgvVDZh N3Q1bVBrYnpTck9MU280cHVqK0lUb05qWXlZSURCV3pobEExOWF2T2ErcnZVam1IdEQzc0ZO N2NYCld0a0dvaThidU5jYnk0VT0KPUFMNm8KLS0tLS1FTkQgUEdQIFBVQkxJQyBLRVkgQkxP Q0stLS0tLQo= Organization: UCLA Computer Science Department Message-ID: <20c80838-5e17-4544-a1f9-e3d862c55b62@cs.ucla.edu> Date: Sat, 22 Aug 2020 14:11:47 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <5F2D377D.5050805@gnu.org> Content-Type: multipart/mixed; boundary="------------CAC0A626A437E918D7A41EDF" Content-Language: en-US X-Spam-Score: -3.2 (---) X-Debbugs-Envelope-To: 28105-done Cc: 28105-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.2 (----) This is a multi-part message in MIME format. --------------CAC0A626A437E918D7A41EDF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 8/7/20 4:14 AM, Antonio Diaz Diaz wrote: > I propose to revert this change to remain consistent with POSIX. It's not a POSIX issue, since POSIX doesn't specify -L, which means grep can do whatever it wants if you specify -L. > But in GNU grep 3.2 to 3.4 -q inverts the exit status when -L is also used. Now 'grep -L > /dev/null' and 'grep -Lq' return opposite values. That is indeed a bug. I looked into this a bit further, and it turns out that when the Git folks were told that git-grep behaved differently from GNU grep 3.1 and earlier, they changed git-grep to match. This was around the same time we changed GNU grep to behave more like the git-grep at the time. What a comedy of errors, huh? Anyway, given all these issues it does seem like it's wise to revert the change. I installed the attached patch into GNU grep master, with the goal of something like this appearing in the next grep release. Thanks for reporting the problem. --------------CAC0A626A437E918D7A41EDF Content-Type: text/x-patch; charset=UTF-8; name="0001-Revert-L-exit-status-change-introduced-in-grep-3.2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Revert-L-exit-status-change-introduced-in-grep-3.2.patc"; filename*1="h" >From 0435ebca64fbafcd62008c991dd9377d8a792dfc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 22 Aug 2020 14:06:26 -0700 Subject: [PATCH] Revert -L exit status change introduced in grep 3.2 Problems reported by Antonio Diaz Diaz in: https://bugs.gnu.org/28105#29 * NEWS, doc/grep.texi (Exit Status), src/grep.c (usage): Adjust documentation accordingly. * src/grep.c (grepdesc, main): Go back to old behavior. * tests/skip-read: Adjust tests accordingly. --- NEWS | 7 +++++++ doc/grep.texi | 3 --- src/grep.c | 10 +++++----- tests/skip-read | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 6abb7c2..5f4c0b4 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,13 @@ GNU grep NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Changes in behavior + + The --files-without-match (-L) option has reverted to its behavior + in grep 3.1 and earlier. That is, grep -L again succeeds when a + line is selected, not when a file is listed. The behavior in grep + 3.2 through 3.4 was causing compatibility problems. + * Noteworthy changes in release 3.4 (2020-01-02) [stable] diff --git a/doc/grep.texi b/doc/grep.texi index 4b26f9d..02b1968 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -1112,9 +1112,6 @@ and only when @env{POSIXLY_CORRECT} is not set. Normally the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred. However, if the -@option{-L} or @option{--files-without-match} is used, the exit status -is 0 if a file is listed, 1 if no files were listed, and 2 if an error -occurred. Also, if the @option{-q} or @option{--quiet} or @option{--silent} option is used and a line is selected, the exit status is 0 even if an error occurred. Other @command{grep} implementations may exit with status diff --git a/src/grep.c b/src/grep.c index 7ba602d..5764b2a 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1864,11 +1864,11 @@ grepdesc (int desc, bool command_line) fflush_errno (); } - status = !count == !(list_files == LISTFILES_NONMATCHING); + status = !count; - if (list_files == LISTFILES_NONE || dev_null_output) + if (list_files == LISTFILES_NONE) finalize_input (desc, &st, ineof); - else if (status == 0) + else if (list_files == (status ? LISTFILES_NONMATCHING : LISTFILES_MATCHING)) { print_filename (); putchar_errno ('\n' & filename_mask); @@ -1997,7 +1997,7 @@ Context control:\n\ printf (_("\ When FILE is '-', read standard input. With no FILE, read '.' if\n\ recursive, '-' otherwise. With fewer than two FILEs, assume -h.\n\ -Exit status is 0 if any line (or file if -L) is selected, 1 otherwise;\n\ +Exit status is 0 if any line is selected, 1 otherwise;\n\ if any error occurs and -q is not given, the exit status is 2.\n")); emit_bug_reporting_address (); } @@ -2835,7 +2835,7 @@ main (int argc, char **argv) /* POSIX says -c, -l and -q are mutually exclusive. In this implementation, -q overrides -l and -L, which in turn override -c. */ - if (exit_on_match) + if (exit_on_match | dev_null_output) list_files = LISTFILES_NONE; if ((exit_on_match | dev_null_output) || list_files != LISTFILES_NONE) { diff --git a/tests/skip-read b/tests/skip-read index 2a17334..1e9e718 100755 --- a/tests/skip-read +++ b/tests/skip-read @@ -15,9 +15,9 @@ for opts in '-m0 y' '-f /dev/null' '-v ""'; do eval returns_ 1 grep -l $opts $matcher /dev/null > out || fail=1 compare /dev/null out || fail=1 done - eval grep -L $opts $matcher /dev/null > out || fail=1 + eval returns_ 1 grep -L $opts $matcher /dev/null > out || fail=1 compare exp out || fail=1 - eval grep -L $opts $matcher /dev/null > /dev/null || fail=1 + eval returns_ 1 grep -L $opts $matcher /dev/null > /dev/null || fail=1 done done -- 2.17.1 --------------CAC0A626A437E918D7A41EDF-- From unknown Tue Jun 24 22:38:59 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 20 Sep 2020 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator