From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 24 03:09:30 2016 Received: (at submit) by debbugs.gnu.org; 24 Jun 2016 07:09:30 +0000 Received: from localhost ([127.0.0.1]:53275 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGLF0-0008Am-Mp for submit@debbugs.gnu.org; Fri, 24 Jun 2016 03:09:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56301) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGGqw-0000tV-C9 for submit@debbugs.gnu.org; Thu, 23 Jun 2016 22:28:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGGqi-0007rx-DQ for submit@debbugs.gnu.org; Thu, 23 Jun 2016 22:28:13 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: *** X-Spam-Status: No, score=3.3 required=5.0 tests=BAYES_50,HTML_MESSAGE, RECEIVED_FROM_WINDOWS_HOST,T_REMOTE_IMAGE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:55218) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGGqi-0007rp-9j for submit@debbugs.gnu.org; Thu, 23 Jun 2016 22:28:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGGqX-0000cH-Je for bug-grep@gnu.org; Thu, 23 Jun 2016 22:28:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGGqO-0007ms-2f for bug-grep@gnu.org; Thu, 23 Jun 2016 22:27:53 -0400 Received: from mail-bn1on0141.outbound.protection.outlook.com ([157.56.110.141]:32096 helo=na01-bn1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGGqN-0007lf-Ny for bug-grep@gnu.org; Thu, 23 Jun 2016 22:27:44 -0400 Received: from DF4PR84MB0172.NAMPRD84.PROD.OUTLOOK.COM (10.162.193.139) by DF4PR84MB0171.NAMPRD84.PROD.OUTLOOK.COM (10.162.193.13) with Microsoft SMTP Server (TLS) id 15.1.523.12; Fri, 24 Jun 2016 02:27:30 +0000 Received: from DF4PR84MB0172.NAMPRD84.PROD.OUTLOOK.COM ([10.162.193.139]) by DF4PR84MB0172.NAMPRD84.PROD.OUTLOOK.COM ([10.162.193.139]) with mapi id 15.01.0523.019; Fri, 24 Jun 2016 02:27:29 +0000 From: "O'Brien, Michael" To: "bug-grep@gnu.org" Subject: grep 2.7 EXIT STATUS inconsistency Thread-Topic: grep 2.7 EXIT STATUS inconsistency Thread-Index: AdHNu60+Mw5jIP8gQ4qmiqYUwCSxlw== Date: Fri, 24 Jun 2016 02:27:29 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=michael.o-brien@hpe.com; x-originating-ip: [96.38.184.158] x-ms-office365-filtering-correlation-id: 98cbc9a2-ec6a-4baa-3dc8-08d39bd71744 x-microsoft-exchange-diagnostics: 1; DF4PR84MB0171; 6:4yIWa9MId7r6nA7z7HH5PddNcopVVJxPAOTUSUpWYKMQE42RLMoDGLWIkXL9mVD//ww7OQ4MOzREFBsIrPeBDW/VGGjcyDT3ihoazCw7JGYh1ZSEfQLdAF5QfeJ/um4eXYL9X5D1EvFwr2md2UHqJFc2HExAfE1D3e2PwRHiCzJn8l1dJx2REQYKl4MyOc8/1tZ6ePPuqgf3TsviOLeGKyZLl9l1jNT8Rfafzn+/aIAEDklGZYG1XsbOtO8dboqamS0BjxbABlfb5xSGqpuDPcfDx2mDKvYRUbxHWqA9h6df/YTucCe1PV4Y3dybxnOl; 5:QN3kEbR1qtdHx7CHkuBJYauOAnoEOuVN6+5b0xyZT7eKrBe+FCnHe9suorarZXWiadXgDXUnfUUsvw+eu+WelZJtCA/sGzL2fVjqLTd517ogZH72A/eU641/XMD5TY4BHwu8K5duLh62cL3H0f1rYg==; 24:ptIzJ597YI8iow3WZM1+04Bbq0TDqbE++rv+SPaUl5V1ZRjJHZOyMxkdj9Ku+GTAqElT6/GX3G9ddcmabPh5fWFfpaBjZo8c/Glx3CSXb6I=; 7:9WA0/MudaPAOYKkcju3z8H3fS/cg8g2u/21c72Kt8XviW4cZ/a7i8k6sALDZUjaZluZbSi7SQYHF1s6avGBKfPzOL9PMvpjSpXlyOHWnr0MvpdGrXn7ZKS95MW/flUQAXD8C4VcsrBRj2xOFko3UoP7QmnBhTWzWR6p/RphPCxHPLlHvnFioxvi4kMNNCyBdHVaU1dW22ZRkJlhCHYf1YzQs4qrKwuQofMT/PKpOsrmmjQlxuAv+oUnFeIv5zCZxRbzAT9p6zlYQ9bY1fisj4g== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0171; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(22074186197030)(260659696264633)(21748063052155)(73583498263828); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:DF4PR84MB0171; BCL:0; PCL:0; RULEID:; SRVR:DF4PR84MB0171; x-forefront-prvs: 0983EAD6B2 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(7916002)(189002)(199003)(584324002)(377424004)(15975445007)(2351001)(7846002)(10400500002)(5640700001)(50986999)(5630700001)(2501003)(2900100001)(19625215002)(86362001)(99286002)(19617315012)(586003)(7736002)(92566002)(8676002)(229853001)(81156014)(81166006)(77096005)(8936002)(66066001)(9686002)(7696003)(5003600100003)(5002640100001)(68736007)(54356999)(101416001)(19580395003)(2906002)(19300405004)(110136002)(33656002)(3280700002)(861006)(18206015028)(97736004)(3660700001)(105586002)(19580405001)(450100001)(122556002)(189998001)(4326007)(19618635001)(16236675004)(106356001)(102836003)(15395725005)(6116002)(3846002)(87936001)(790700001)(7906003)(7099028)(2004002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR84MB0171; H:DF4PR84MB0172.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_DF4PR84MB017292B777EB48C285F4B142B12E0DF4PR84MB0172NAMP_" MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jun 2016 02:27:29.7511 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0171 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 24 Jun 2016 03:09:26 -0400 Cc: "Desostoa, Chuck \(ES\)" , "Lenahan, Mike" 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: -5.0 (-----) --_000_DF4PR84MB017292B777EB48C285F4B142B12E0DF4PR84MB0172NAMP_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable GNU grep team, I've found some inconsistency with the EXIT STATUS processing of grep 2.7. = All data used in the test is shown below, along with the command line arg= uments to grep. Everything needed to repeat my test cases is described in= this email. Below are the details. Version Information: > grep --version grep (GNU grep) 2.7 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and others, see . > Details: >From the Manual page of grep, the text of the EXIT STATUS follows: EXIT STATUS Normally, the exit status is 0 if selected lines are found and 1 oth= erwise. But the exit status is 2 if an error occurred, unless the -q or --quiet or --silent option is used and a selected line= is found. Note, however, that POSIX only mandates, for programs such as grep, cmp, and diff, that the exit status in case of error b= e greater than 1; it is therefore advisable, for the sake of portability, to use logic that tests for this general condition inst= ead of strict equality with 2. Below are two test cases that show the EXIT STATUS from grep is not necessa= rily described as "Normally, the exit status is 0 if selected lines are fou= nd and 1 otherwise". * Note1: $GREP_EXCLUDE used below is simply a shell variable pointi= ng to a file containing the lines to exclude from the output, and set with = a command similar too: GREP_EXCLUDE=3D./testing.grep_exclude * Note2: During the testing below, the *only change* was to the con= tents of the $GREP_EXCLUDE file. * Note3: The input data remained the same between test cases. * Note4: The input data is ascii text, with each line terminated wi= th a newline. Each line in the input file begins with the pattern: "n,n,"= and continues to the EOL, or newline character. There are 7 lines in the = input file. Test case one will show the return code from grep when the -ivEF "exclude" = removes *all* data records from the input. Notice, the input file is fed = to grep, and there's no output -- in other words, all records were (or "sel= ected to be") excluded. The return code (or EXIT STATUS) is 1. Thu Jun 23 22:12:46 UTC 2016 Test Case 1: grep exclude file with filters that will exclude all data from= input hpehrshdev:~/tmp> cat mjodata.txt | grep -ivEf $GREP_EXCLUDE hpehrshdev:~/tmp> echo $? 1 hpehrshdev:~/tmp> cat mjodata.txt 0,5,"2016-06-17 16:30:54.404000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 16:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D1, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 16:30:53.0000000." 0,5,"2016-06-17 15:30:54.158000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 15:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 15:30:53.0000000." 0,5,"2016-06-17 14:30:53.780000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 14:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 14:30:53.0000000." 0,5,"2016-06-17 13:30:54.906000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 13:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 13:30:53.0000000." 0,5,"2016-06-17 12:30:54.665000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 12:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 12:30:53.0000000." 77,4,"2016-06-17 12:30:56.582000000","The disk usage of this database has e= xceeded 7498 GB. See system view M_DISK_USAGE for more details." 69,4,"2016-06-17 12:33:20.228000000","Automatic log backup is disabled." hpehrshdev:~/tmp> hpehrshdev:~/tmp> hpehrshdev:~/tmp> cat $GREP_EXCLUDE ^69,4,.*Automatic log backup is disabled.*$ ^77,4,.*The disk usage of this database has exceeded.*See system view M_DIS= K_USAGE for more details.*$ ^0,5,.*301 unique constraint violated: TrexUpdate failed on table hpehrshdev:~/tmp> Test case two will show the return code from grep when the -ivEF "exclude" = removes *only some* of the data records from the input. Notice, the input= file is fed to grep, and output is returned -- in other words, some record= s were (selected to be) excluded, but some of the records did not get exclu= ded (because there was no filter for them). The return code (or EXIT STAT= US) is 0. Thu Jun 23 22:15:35 UTC 2016 Test Case 2: grep exclude file with filters that will exclude some of the d= ata from input hpehrshdev:~/tmp> cat mjodata.txt | grep -ivEf $GREP_EXCLUDE 0,5,"2016-06-17 16:30:54.404000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 16:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D1, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 16:30:53.0000000." 0,5,"2016-06-17 15:30:54.158000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 15:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 15:30:53.0000000." 0,5,"2016-06-17 14:30:53.780000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 14:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 14:30:53.0000000." 0,5,"2016-06-17 13:30:54.906000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 13:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 13:30:53.0000000." 0,5,"2016-06-17 12:30:54.665000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 12:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 12:30:53.0000000." hpehrshdev:~/tmp> echo $? 0 hpehrshdev:~/tmp> cat mjodata.txt 0,5,"2016-06-17 16:30:54.404000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 16:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D1, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 16:30:53.0000000." 0,5,"2016-06-17 15:30:54.158000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 15:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 15:30:53.0000000." 0,5,"2016-06-17 14:30:53.780000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 14:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 14:30:53.0000000." 0,5,"2016-06-17 13:30:54.906000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 13:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 13:30:53.0000000." 0,5,"2016-06-17 12:30:54.665000000","[29] 301 unique constraint violated: T= rexUpdate failed on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with err= or: unique constraint violation in self check for table _SYS_STATISTICS:STA= TISTICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17= 12:30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TRE= E_CS_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 12:30:53.0000000." 77,4,"2016-06-17 12:30:56.582000000","The disk usage of this database has e= xceeded 7498 GB. See system view M_DISK_USAGE for more details." 69,4,"2016-06-17 12:33:20.228000000","Automatic log backup is disabled." hpehrshdev:~/tmp> cat $GREP_EXCLUDE ^69,4,.*Automatic log backup is disabled.*$ ^77,4,.*The disk usage of this database has exceeded.*See system view M_DIS= K_USAGE for more details.*$ hpehrshdev:~/tmp> Issue: In scripting, it is normal to process the EXIT STATUS of grep in such a way= that an EXIT STATUS of 0 (zero) indicates that matches to the grep pattern= were found. In *both of* the above test cases matches *were* found, yet = the EXIT STATUS was not consistently 0. In test case 1, *all* records were= matched, yet the EXIT STATUS was 1. With this behaviour of grep, it is * = not possible to correctly* perform the following simple logic (bash syntax)= : typeset -i RC=3D0 cat mjodata.txt | grep -ivEf $GREP_EXCLUDE RC=3D$? if [ $RC -eq 0 ]; then #Grep found matches #Do something... else #No match found, or possibly some error -- needs more checking fi Michael J. O'Brien Consultant Architect, AMS ABS Global Practice michael.o-brien@hpe.com +1 650 258 2628 Office +1 916 335 3010 Mobile US/Pacific time zone hpe.com [HPE logo] --_000_DF4PR84MB017292B777EB48C285F4B142B12E0DF4PR84MB0172NAMP_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

GNU grep team,

 

I’ve found some inconsistency with the EXIT ST= ATUS processing of grep 2.7.   All data used in the test is shown= below, along with the command line arguments to grep.   Everythi= ng needed to repeat my test cases is described in this email.  Below are the details.

 

Version Informat= ion:

 

> grep --version

grep (GNU grep) 2.7

Copyright (C) 2010 Free Software Foundation, Inc= .

License GPLv3+: GNU GPL version 3 or later &= lt;http://gnu.org/licenses/gpl.html>.

This is free software: you are free to change an= d redistribute it.

There is NO WARRANTY, to the extent permitted by= law.

 

Written by Mike Haertel and others, see <http= ://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

> 

 

Details:

 

From the Manual page of g= rep, the text of the EXIT STATUS follows:

 

EXIT STATUS

       Normally, the exit s= tatus is 0 if selected lines are found and 1 otherwise.  But th= e exit status is 2 if an  error  occurred,  unless

       the  = -q  or  --quiet  or --silent option is used and a selected l= ine is found.  Note, however, that POSIX only mandates, for programs

       such as gr= ep, cmp, and diff, that the exit status in case of error be greater than 1;= it is therefore  advisable,  for  the  sake  of

       portabilit= y, to use logic that tests for this general condition instead of strict equ= ality with 2.

 

Below are two test cases = that show the EXIT STATUS from grep is not necessarily described as “= Normally, the exit stat= us is 0 if selected lines are found and 1 otherwise”.   

·         Note1: $GREP_EXCLUDE used below is simply a shell variable p= ointing to a file containing the lines to exclude from the output, and set = with a command similar too: GREP_EXCLUDE=3D./testin= g.grep_exclude

·         Note2: During the testing below, the *onl= y change* was to the contents of the $GREP_EXCLUDE= file.  

·         Note3: The input data remained the same betw= een test cases.  

·         Note4: The input data is ascii text, with ea= ch line terminated with a newline.   Each line in the input file = begins with the pattern: “n,n,” and continues to the EOL, or ne= wline character.  There are 7 lines in the input file.

 

Test case one will show = the return code from grep when the -ivEF “exclude” removes *= all* data records from the input.   Notice, the input file is= fed to grep, and there’s no output -- in other words, all records were (or “selected to be”) excluded.   The return code (o= r EXIT STATUS) is 1.=

 

Thu Jun 23 22:12:46 UTC 2016

Test Case 1: grep exclude file = with filters that will exclude all data from input

hpehrshdev:~/tmp> cat mjodata.txt | grep -ivEf $GREP_EXCLUDE

hpehrshdev:~/tmp> echo $?

1

hpehrshdev:~/tmp> cat mjodata.txt

0,5,"2016-06-17 16:30:54.4= 04000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 16= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D1, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 16:30:53.0000000."

0,5,"2016-06-17 15:30:54.1= 58000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 15= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 15:30:53.0000000."

0,5,"2016-06-17 14:30:53.7= 80000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 14= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 14:30:53.0000000."

0,5,"2016-06-17 13:30:54.9= 06000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 13= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 13:30:53.0000000."

0,5,"2016-06-17 12:30:54.6= 65000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 12= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 12:30:53.0000000."

77,4,"2016-06-17 12:30:56.= 582000000","The disk usage of this database has exceeded 7498 GB.= See system view M_DISK_USAGE for more details."

69,4,"2016-06-17 12:33:20.= 228000000","Automatic log backup is disabled."

hpehrshdev:~/tmp>=

hpehrshdev:~/tmp>=

hpehrshdev:~/tmp> cat $GREP_EXCLUDE

^69,4,.*Automatic log backup is disabled.*$

^77,4,.*The disk usage of this database has exceeded.*See system vi= ew M_DISK_USAGE for more details.*$

^0,5,.*301 unique constraint violated: TrexUpdate failed on table

hpehrshdev:~/tmp>=

 

Test case two will show = the return code from grep when the -ivEF “exclude” removes *= only some* of the data records from the input.   Notice, the = input file is fed to grep, and output is returned -- in other words, some records were (selected to be) excluded, but some of the records did not get= excluded (because there was no filter for them).   The return co= de (or EXIT STATUS) is 0.=

 

Thu Jun 23 22:15:35 UTC 2016

Test Case 2: grep exclude file = with filters that will exclude some of the data from input

hpehrshdev:~/tmp> cat mjodata.txt | grep -ivEf $GREP_EXCLUDE

0,5,"2016-06-17 16:30:54.4= 04000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 16= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D1, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 16:30:53.0000000."

0,5,"2016-06-17 15:30:54.1= 58000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 15= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 15:30:53.0000000."

0,5,"2016-06-17 14:30:53.7= 80000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 14= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 14:30:53.0000000."

0,5,"2016-06-17 13:30:54.9= 06000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 13= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 13:30:53.0000000."

0,5,"2016-06-17 12:30:54.6= 65000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 12= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 12:30:53.0000000."

hpehrshdev:~/tmp> echo $?

0

hpehrshdev:~/tmp> cat mjodata.txt

0,5,"2016-06-17 16:30:54.4= 04000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 16= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D1, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 16:30:53.0000000."

0,5,"2016-06-17 15:30:54.1= 58000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 15= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 15:30:53.0000000."

0,5,"2016-06-17 14:30:53.7= 80000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 14= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D3, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 14:30:53.0000000."

0,5,"2016-06-17 13:30:54.9= 06000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 13= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 13:30:53.0000000."

0,5,"2016-06-17 12:30:54.6= 65000000","[29] 301 unique constraint violated: TrexUpdate failed= on table '_SYS_STATISTICS:STATISTICS_ALERTS_BASE' with error: unique constraint violation in self check for table _SYS_STATISTICS:STATIS= TICS_ALERTS_BASEen, constraint=3D'$trexexternalkey$', udiv=3D'2016-06-17 12= :30:53;29;27,PBM_ECC_DB.ZFE_FDSTAGDETAIL', pos=3D4, indexname=3D_SYS_TREE_C= S_#145806_#0_#P0, rc=3D55 SNAPSHOT_ID: 2016-06-17 12:30:53.0000000."

77,4,"2016-06-17 12:30:56.= 582000000","The disk usage of this database has exceeded 7498 GB.= See system view M_DISK_USAGE for more details."

69,4,"2016-06-17 12:33:20.= 228000000","Automatic log backup is disabled."

hpehrshdev:~/tmp> cat $GREP_EXCLUDE

^69,4,.*Automatic log backup is disabled.*$

^77,4,.*The disk usage of this database has exceeded.*See system vi= ew M_DISK_USAGE for more details.*$

hpehrshdev:~/tmp>

 

Issue:

 

In scripting, it is norma= l to process the EXIT STATUS of grep in such a way that an EXIT STATUS of 0= (zero) indicates that matches to the grep pattern were found.   = In *both of* the above test cases matches *were* found, yet the EXIT STATUS was not consistently 0.  In = test case 1, *all* records were matched, yet the EXIT STATUS was 1.&= nbsp; With this behaviour of grep, it is * not possible to correctly* perform the following simple logic= (bash syntax):

 

typeset -i RC=3D0

 

cat mjodata.txt | grep -ivEf $GREP_EXCLUDE<= /o:p>

RC=3D$?

 

if [ $RC -eq 0 ]; then

     #Grep found matches

     #Do something…

else

     #No match found, or pos= sibly some error -- needs more checking

fi

 

 

Michael J. O'Brien
Consultant Architect, AMS ABS Global Practice

michael.o-brien@hpe.com

+1 650 258 2628  Office
+1 916 335 3010  Mobile

US/Pacific time zone
hpe= .com


 

--_000_DF4PR84MB017292B777EB48C285F4B142B12E0DF4PR84MB0172NAMP_-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 24 04:37:05 2016 Received: (at 23837-done) by debbugs.gnu.org; 24 Jun 2016 08:37:05 +0000 Received: from localhost ([127.0.0.1]:53365 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGMbp-00029m-CB for submit@debbugs.gnu.org; Fri, 24 Jun 2016 04:37:05 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:50098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGMbn-00029I-Fv for 23837-done@debbugs.gnu.org; Fri, 24 Jun 2016 04:37:03 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8260A161489; Fri, 24 Jun 2016 01:36:56 -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 PNEqg_DWP3Wl; Fri, 24 Jun 2016 01:36:55 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id CEFA51614DF; Fri, 24 Jun 2016 01:36:55 -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 gMWTabBfuoEU; Fri, 24 Jun 2016 01:36:55 -0700 (PDT) Received: from [192.168.1.2] (host82-219-dynamic.32-79-r.retail.telecomitalia.it [79.32.219.82]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id B4958161489; Fri, 24 Jun 2016 01:36:54 -0700 (PDT) Subject: Re: bug#23837: grep 2.7 EXIT STATUS inconsistency To: "O'Brien, Michael" , 23837-done@debbugs.gnu.org References: From: Paul Eggert Message-ID: <576CF11E.9070305@cs.ucla.edu> Date: Fri, 24 Jun 2016 10:36:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: 23837-done Cc: "Desostoa, Chuck \(ES\)" , "Lenahan, Mike" 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: -1.4 (-) On 06/24/2016 04:27 AM, O'Brien, Michael wrote: > Notice, the input file is fed to grep, and there's no output -- in other words, all records were (or "selected to be") excluded. No, -v inverts the sense of matching, so that non-matching lines are selected. So there is no bug here. From unknown Mon Aug 18 15:41:42 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, 22 Jul 2016 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