From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 Resent-From: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Tue, 24 Jun 2025 14:36:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 78891@debbugs.gnu.org X-Debbugs-Original-To: bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.175077571217439 (code B ref -1); Tue, 24 Jun 2025 14:36:04 +0000 Received: (at submit) by debbugs.gnu.org; 24 Jun 2025 14:35:12 +0000 Received: from localhost ([127.0.0.1]:44932 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uU4jn-0004UW-0t for submit@debbugs.gnu.org; Tue, 24 Jun 2025 10:35:11 -0400 Received: from lists.gnu.org ([2001:470:142::17]:51634) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uU0Hj-0006kJ-Fc for submit@debbugs.gnu.org; Tue, 24 Jun 2025 05:49:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uU0Hd-0006gu-Ns for bug-grep@gnu.org; Tue, 24 Jun 2025 05:49:41 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU0HY-0002yu-OF for bug-grep@gnu.org; Tue, 24 Jun 2025 05:49:41 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-ae0a420431bso166082466b.2 for ; Tue, 24 Jun 2025 02:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750758573; x=1751363373; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=4hkZ0LCM15xPRbawFSA4WVgoj9ygPL+LsUHo82n/saI=; b=K0MmPA9s19oNOzt2rmMvKDMXupvdDNv7n95NbYAMkAyHRltlrg9W0lmcv/rt9BDI1O 3BISNumb1tMTUwaDwbmcxaaCTkDIrCMRQX9t7CtsrWLQkaIPOnyMJF5YukTRjDDW8h4I /nNs9Zr7HA26ik0uY57qMTXqrUbBzVFk7y+27akAWq9D0JMhmt7vXrIPqYjWQYQsS2W3 0MDAopap8HN/2J/Z8hFrW19TGtG1Jy7B3TQFq1sLk/CS9QbeF/PN04+kaBAyVRXfEmpu FHRG1ayFq/csCE7j5pPLEswbevJujbOqKg7xhnzSy4/kKOa9TAh5iNxHQfNW+jafu/86 M8yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750758573; x=1751363373; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4hkZ0LCM15xPRbawFSA4WVgoj9ygPL+LsUHo82n/saI=; b=MliTHezn3snoc81X4rdtYSQKPDwrxXUfi7jPqumhRAkZCzWlNtJRJ54tDVVE1xRAOr rWTPWQt6koa+RyQ+nrusNn7zaWhm9jS62yF+wfTITz6QpydnF/QhgOmrM1AAtQ5DzE4b IxAhl72pNyJxHmu2Yt/AqKEIKEOuho3WMJ+PMdsDOhoo0UHidHNws1PQ7VenDu+4fsWW l0ZXq2F6hW9eTMdaaETDI93VkbhdXx+Cs0ktwzjbCpegr7QCqsFkGK18gsr6Dpq1woca H9BJiV94C6dKbga5iKOL0auRbPS0eaQlvxZcTykzuvOZXGe0TehBUkyxzZJDi3Jw7TOq 128w== X-Gm-Message-State: AOJu0Yw1XiWG70zDuZiWTBYufE/iRPQlyjUNQJqOleAMNeQhoD86ZhOw BJPFxxB9wbJe3VFoqPbgiQ2HtPHUHa3YmFn93tdtahkZGrfEnyfZc6/2/c+ddYi7anotYsTgDWK GNrus1CGmpBF2V9FASzm4OEJE10NbNIt301bm+dCOdw== X-Gm-Gg: ASbGnct2JNyx6Z9TNAr6RHUkzVjyxfMAjG9Yg1cVAgsokxdoIdJIDiidiT7L0bQM8ZY K6MBXgTaLBXozq1BTaKjXjJvJ1tc6RqaETWNK9gGaJH+rrxH978B7iiJHLA7qNDFP3yNW5xMqG4 /SAygDTsksY3DZiMZcJeFQImVQD9SiDNiR1bNTLN1nTjjEbAFQ9P0Qws4L9OJ3fvH3zpS7kph3O w== X-Google-Smtp-Source: AGHT+IFn+DBjJR9eCZ+f1mRul8hAieV5LE68RXMs9Z0B8425/25vAptmZmql4n7RXd6xIEVjfTKHKbGaz9l8NRkrqZM= X-Received: by 2002:a17:906:9f90:b0:ade:484d:1518 with SMTP id a640c23a62f3a-ae057ac2874mr1193909366b.26.1750758572242; Tue, 24 Jun 2025 02:49:32 -0700 (PDT) MIME-Version: 1.0 From: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Date: Tue, 24 Jun 2025 11:49:21 +0200 X-Gm-Features: Ac12FXzTpLrCnfVJUG8p-zhHmAI1GlJQPVzYQA0ZKw5bJFWSO58jEt07zXIx5bI Message-ID: Content-Type: multipart/alternative; boundary="000000000000c9445c06384e3eec" Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=guettliml@gmail.com; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Mailman-Approved-At: Tue, 24 Jun 2025 10:35:00 -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: -0.0 (/) --000000000000c9445c06384e3eec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, after trying several tools like SaltStack and Ansible and several CI tools, I came to the conclusion that a Bash script is often the most convenient and powerful solution. To make Bash more robust, I use the "strict mode". This works fine, except that very often I want to filter out some output, and it does not matter to me if there is a match or not. Afaik there is no option to make `grep` always exit with a zero exit status. No matter if a match was found or not. Errors like "file not found" should still return a non-zero exit status. Just out of curiosity, would you accept a patch to implement that? Which command line argument could be used for that option? Regard, Thomas G=C3=BCttler --000000000000c9445c06384e3eec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

after trying several tools like Sal= tStack and Ansible and several CI tools, I came
to the conclusion= that a Bash script is often the most convenient and powerful solution.

To make Bash more robust, I use the "strict mode= ".

This=C2=A0works fine, except that very oft= en I want to filter out some output, and it
does not matter to me= if there is a match or not.

Afaik there is no opt= ion to make `grep` always exit with a zero exit status. No matter if a matc= h was found or not. Errors like "file not found" should still ret= urn a non-zero exit status.

Just out of=C2=A0curiosity, would you ac= cept a patch to implement that?

Which command line= argument could be used for that option?

Regard,
=C2=A0 Thomas G=C3=BCttler

--000000000000c9445c06384e3eec-- From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 References: Resent-From: "Dale R. Worley" Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Tue, 24 Jun 2025 18:23:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Cc: 78891@debbugs.gnu.org Received: via spool by 78891-submit@debbugs.gnu.org id=B78891.175078936229497 (code B ref 78891); Tue, 24 Jun 2025 18:23:04 +0000 Received: (at 78891) by debbugs.gnu.org; 24 Jun 2025 18:22:42 +0000 Received: from localhost ([127.0.0.1]:48236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uU8I5-0007fc-DV for submit@debbugs.gnu.org; Tue, 24 Jun 2025 14:22:41 -0400 Received: from resdmta-h2p-565048.sys.comcast.net ([2001:558:fd02:2446::c]:25274) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uU8I2-0007ed-Pn for 78891@debbugs.gnu.org; Tue, 24 Jun 2025 14:22:39 -0400 Received: from resomta-h2p-540626.sys.comcast.net ([96.102.179.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 256/256 bits) (Client did not present a certificate) by resdmta-h2p-565048.sys.comcast.net with ESMTPS id U4U4uXmShkakVU8HvuFjHg; Tue, 24 Jun 2025 18:22:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1750789351; bh=EU4OQrTpaGbvamTgH8OtmxthWvReSkQRjT91BhKc41Q=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Xfinity-Spam-Result; b=MixiV7ohLEN29ghfW1sPcu95ovKUwJIOfYXb4begnhWjbekSKvDa0kme2Wiprhp9d q8Ic3Y3oIijXgiLkn8kwBPVSFg6fUzAuddZeeMpDsJYF6Z19dmY7+udn9z/JYk5yZN Scqsh/dSCaTrPNoa4OpQdPNgfniMVlZ7iyELadEPWRVIpr15kfLFcKDcQpuyHLAUQj fDnGtzIxkGUPoLDfOkSLwV48GkzAlYk7wetEiDs5iuxIi1CO1KPusT7l16A4ObiwmL ROlWNZRf75rRKkkunCNLlnlA88sZoCAOV3An44ixqlInO2cNiAwGrGxILqBt2AVaBI NRsbYOKthaZYg== Received: from hobgoblin.ariadne.com ([IPv6:2601:192:4a00:430::4b00]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 256/256 bits) (Client did not present a certificate) by resomta-h2p-540626.sys.comcast.net with ESMTPSA id U8Htu9yH0GKnQU8Huu18R5; Tue, 24 Jun 2025 18:22:31 +0000 Received: from hobgoblin.ariadne.com (localhost [127.0.0.1]) by hobgoblin.ariadne.com (8.16.1/8.16.1) with ESMTPS id 55OIMSAw2996467 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 24 Jun 2025 14:22:28 -0400 Received: (from worley@localhost) by hobgoblin.ariadne.com (8.16.1/8.16.1/Submit) id 55OIMSNn2996464; Tue, 24 Jun 2025 14:22:28 -0400 X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to Dale.Worley@comcast.net using -f From: "Dale R. Worley" In-Reply-To: (guettliml@gmail.com) Date: Tue, 24 Jun 2025 14:22:28 -0400 Message-ID: <8734bphue3.fsf@hobgoblin.ariadne.com> X-CMAE-Envelope: MS4xfKNPUZ5UTlFrDu756ewn9TfB+4y6JWXNmHPUyS68vefL6gpuwBKvR/a80UPzPg7/c9txiLRt5fTWNHzboarJeXy3+aXy7HxwEeUJ5jESrXT16LG5Vyfy c8hYu8d3W7s83JGMFrmveOrFo+fZoaHcte3TXVLvrkm6KSjogZko4XfUG7qSwc8mYt3sQ+08WqqzCj9RixPJRKnyAzFcBmU+HmwKQo3psPShXZOOT4jpqj6i sMQ7g+2uvm6FjNng/tCNbAzqVJeCSqtHFMxoLmcwd74= X-Spam-Score: 0.2 (/) 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.8 (/) Thomas Güttler Mailinglisten writes: > To make Bash more robust, I use the "strict mode". > > This works fine, except that very often I want to filter out some > output, and it does not matter to me if there is a match or not. > > Afaik there is no option to make `grep` always exit with a zero exit > status. No matter if a match was found or not. Errors like "file not found" > should still return a non-zero exit status. Well, this isn't what you asked for, but it's a reasonaby terse way to get the effect without modifying grep: grep ... || [[ $? != 2 ]] That has an exit status of 1 if grep exits with 2, and an exit status of 0 otherwise. Dale From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 Resent-From: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Wed, 25 Jun 2025 05:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: Cc: 78891@debbugs.gnu.org Received: via spool by 78891-submit@debbugs.gnu.org id=B78891.17508293524844 (code B ref 78891); Wed, 25 Jun 2025 05:30:03 +0000 Received: (at 78891) by debbugs.gnu.org; 25 Jun 2025 05:29:12 +0000 Received: from localhost ([127.0.0.1]:56561 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uUIh5-0001G2-GK for submit@debbugs.gnu.org; Wed, 25 Jun 2025 01:29:11 -0400 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]:61576) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uUIh2-0001Ey-H7 for 78891@debbugs.gnu.org; Wed, 25 Jun 2025 01:29:09 -0400 Received: by mail-ej1-x643.google.com with SMTP id a640c23a62f3a-adb2bd27c7bso940383366b.2 for <78891@debbugs.gnu.org>; Tue, 24 Jun 2025 22:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750829342; x=1751434142; darn=debbugs.gnu.org; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=iICYsnve1wPmaLDuLduGf4m7DBFZl2rdt9pc7VAWShQ=; b=LB6S6zMDVmfaPNum/PJAhsjAJRtYk0V9gxeiozlievFqB2gm3cZJb/0pxZ1rNlS05a kudqw8xfr4dxT7fHXm7zuYgp8HUYTJurryS8lAvJToNGntm2vqQS3wLmfXA+xnNSvFo2 Qif2W6AydMa70lpio1dfrr47QVtphY9xJ0TK+B2AvCxoX2/R8y/NoAsUazJ4edjOXalT RTU9UUNktzySHX92n7Kgq6jwXRp/yXXDzIIkL08Sl8TyrfQRvC70njQosvOdtO/5z8Tq B4bGhiGZvRSdxcH//PwW0sCdIN9951CDcpbHcIn3oEu32LePFO6mF+kKAlE+rEv63NlE X1wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750829342; x=1751434142; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iICYsnve1wPmaLDuLduGf4m7DBFZl2rdt9pc7VAWShQ=; b=TKFkf3CkNEFEIHSlOFPT8K1t/ET9wYqjSfJK3SOqSQmvzP1GfWwV/l3v+XiQykYcdF UcBVO2AsFRYbGyY6Sl9fnm6b56nAQ/ygoJGd+5SS3tEEVMS+UHoarEAWviflOrFyzduF BWUUz1+8m6mJ29YYIhSoszUZ7eLSGVPFJsmJi9Z7ZjsCMmFqZCYUQc9PQpxNVwLwuDkw itO7yJrx74K/F/x0rVs9TH4Dz+7ycgeV3iT379kWrlP57vLTv+zXIn60CEJ8oGa70zEu IKa8CWKng6qM0yvlychNIN4Cm8e8GXY1VUvxZyC0qWk2emqNY6FOdbPPtpFyj6D0Ce7/ usFQ== X-Gm-Message-State: AOJu0YxURdRr+4dphjWXP83og5MWSGfT2EWjYSU6nyXe/B1t/MzLfuvy 1+n/V8Q7f4MZ8R6zORnUENTFAU9ByveuRU/huK2e6SH/Nh14tWogK2fuWRV4N3GxcdJcSuEb2Do LzB8qq39s7fzxfjtqKbUmpGVcnMM3BXX+j+4sqIMiFgPb X-Gm-Gg: ASbGncvzx12niCJXiIXjdCGmtmZtLmi65FPN/Pf6wv9SMcV83CXIIKyavWnebT/yHda Ks1Fj2KLAHt5URb5IpN+6u4q6OTgMrB2zVDEVRVWRtIGSPakSTfJhepcme3SfvYMcOcsSjAhOBl uzbp0laiQnEz8nu4UemhgzJT2FInHG4/dFrkb+1+4NtWO1ZI/7+84r7DDAlaY0qt9/g0QTUl1OV w== X-Google-Smtp-Source: AGHT+IGhi4tZDOLxGMaxJTMbJKPMNmLJ2QzCodhG1Fu9Es3ieLhiw6eRa/+zLtAR6VK60LrhGSHgqRxeNtaaXQeGdzQ= X-Received: by 2002:a17:907:1ca1:b0:ade:8d5a:cf37 with SMTP id a640c23a62f3a-ae0bea04809mr179204366b.44.1750829341173; Tue, 24 Jun 2025 22:29:01 -0700 (PDT) MIME-Version: 1.0 References: <8734bphue3.fsf@hobgoblin.ariadne.com> In-Reply-To: <8734bphue3.fsf@hobgoblin.ariadne.com> From: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Date: Wed, 25 Jun 2025 07:28:49 +0200 X-Gm-Features: Ac12FXxPitdg-dwlsys0UbJnixveqlAYQTmGPEVnUjT66XivfzX453jOFFipURM Message-ID: Content-Type: multipart/alternative; boundary="000000000000f16afc06385eb880" X-Spam-Score: 1.2 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi Dale, thank you for your reply. Currently, I work around like this: echo -e "foo\nbar" | { grep '^#' >comments.txt || true; } | some-other-command Related: My Bash Strict Mode. Handle non-zero exit codes Content analysis details: (1.2 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (guettliml[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:643 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 1.2 MISSING_HEADERS Missing To: header 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 HTML_MESSAGE BODY: HTML included in message 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.2 (/) --000000000000f16afc06385eb880 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Dale, thank you for your reply. Currently, I work around like this: echo -e "foo\nbar" | { grep '^#' >comments.txt || true; } | some-other-command Related: My Bash Strict Mode. Handle non-zero exit codes This works, but it is not nice to read and more typing. There are many ways to work around that. During the last months I wrote a lot of Bash code, and often I needed to handle the non-zero exit code of grep. It would be handy to have an option to make grep always return zero (except "file not found" or similar errors). Why not? Before creating a patch, I would like to know which command line option you prefer. There are not many characters left, which could be used. What about `-g` like "good, even if nothing was found"? Or `-t` like always return true (zero exit status). But first: Would a patch be acceptable? Regards, Thomas Am Di., 24. Juni 2025 um 20:22 Uhr schrieb Dale R. Worley < Dale.Worley@comcast.net>: > Thomas G=C3=BCttler Mailinglisten writes: > > To make Bash more robust, I use the "strict mode". > > > > This works fine, except that very often I want to filter out some > > output, and it does not matter to me if there is a match or not. > > > > Afaik there is no option to make `grep` always exit with a zero exit > > status. No matter if a match was found or not. Errors like "file not > found" > > should still return a non-zero exit status. > > Well, this isn't what you asked for, but it's a reasonaby terse way to > get the effect without modifying grep: > > grep ... || [[ $? !=3D 2 ]] > > That has an exit status of 1 if grep exits with 2, and an exit status of > 0 otherwise. > > Dale > --000000000000f16afc06385eb880 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Dale, thank you for your reply. Currently, I work = around like this:

echo -e "foo\nbar" | { grep &= #39;^#' >comments.txt || true; } | some-other-command

=

Thi= s works, but it is not nice to read and more typing.

There are many ways to work around=C2=A0that. During the last months I w= rote=C2=A0
a lot of Bash code, and often I needed to handle the n= on-zero exit code of grep.

It would be handy to ha= ve an option to make grep always=C2=A0return zero (except "file not fo= und" or similar errors).

Why not?
<= br>
Before creating a patch, I would like to know which command l= ine option you prefer.

There are not many characte= rs=C2=A0left, which could be used.

What about `-g`= like "good, even if nothing was found"?

Or `-t` like always return true (zero exit status).

But first: Woul= d a patch be acceptable?

Regards,
=C2=A0= Thomas



Am Di= ., 24. Juni 2025 um 20:22=C2=A0Uhr schrieb Dale R. Worley <Dale.Worley@comcast.net>:
Thomas G=C3=BCttler Mailingl= isten <guettlim= l@gmail.com> writes:
> To make Bash more robust, I use the "strict mode".
>
> This works fine, except that very often I want to filter out some
> output, and it does not matter to me if there is a match or not.
>
> Afaik there is no option to make `grep` always exit with a zero exit > status. No matter if a match was found or not. Errors like "file = not found"
> should still return a non-zero exit status.

Well, this isn't what you asked for, but it's a reasonaby terse way= to
get the effect without modifying grep:

=C2=A0 =C2=A0 grep ... || [[ $? !=3D 2 ]]

That has an exit status of 1 if grep exits with 2, and an exit status of 0 otherwise.

Dale
--000000000000f16afc06385eb880-- From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 Resent-From: Martin Schulte Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Wed, 25 Jun 2025 06:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Cc: 78891@debbugs.gnu.org Received: via spool by 78891-submit@debbugs.gnu.org id=B78891.175083179025457 (code B ref 78891); Wed, 25 Jun 2025 06:10:02 +0000 Received: (at 78891) by debbugs.gnu.org; 25 Jun 2025 06:09:50 +0000 Received: from localhost ([127.0.0.1]:57114 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uUJKP-0006cW-T9 for submit@debbugs.gnu.org; Wed, 25 Jun 2025 02:09:50 -0400 Received: from sb.ds-gmbh.de ([91.184.37.131]:46706) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uUJKN-0006c1-CA for 78891@debbugs.gnu.org; Wed, 25 Jun 2025 02:09:47 -0400 Received: from gwp.linuxhotel.de ([185.232.103.116] helo=martnix4.ds-gmbh.de) by sb.ds-gmbh.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uUJKL-0003uG-Cq; Wed, 25 Jun 2025 08:09:45 +0200 Date: Wed, 25 Jun 2025 08:09:43 +0200 From: Martin Schulte Message-Id: <20250625080943.c81b411fafcdf73755526ec1@schrader-schulte.de> In-Reply-To: References: <8734bphue3.fsf@hobgoblin.ariadne.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Score: -2.7 (--) 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.7 (---) Hello Thomas! > echo -e "foo\nbar" | { grep '^#' >comments.txt || true; } | > some-other-command > > Related: My Bash Strict Mode. Handle non-zero exit codes > > > This works, but it is not nice to read and more typing. What about a grep_always_true() { grep "$@" || true } ? Best regards, Martin From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Wed, 25 Jun 2025 17:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Cc: 78891@debbugs.gnu.org Received: via spool by 78891-submit@debbugs.gnu.org id=B78891.17508717768963 (code B ref 78891); Wed, 25 Jun 2025 17:17:02 +0000 Received: (at 78891) by debbugs.gnu.org; 25 Jun 2025 17:16:16 +0000 Received: from localhost ([127.0.0.1]:38397 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uUTjL-0002KQ-Pu for submit@debbugs.gnu.org; Wed, 25 Jun 2025 13:16:16 -0400 Received: from mail.cs.ucla.edu ([131.179.128.66]:43268) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uUTi7-00026L-Sx for 78891@debbugs.gnu.org; Wed, 25 Jun 2025 13:15:01 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 169813C00D409; Wed, 25 Jun 2025 10:14:53 -0700 (PDT) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id YNzq8j4Ypikh; Wed, 25 Jun 2025 10:14:53 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id E3EFC3C00D40F; Wed, 25 Jun 2025 10:14:52 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu E3EFC3C00D40F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1750871692; bh=G9Y3ey7U3hvseGdnAcP0Z0Gs04Kb4kCH2kt49LPIq6M=; h=Message-ID:Date:MIME-Version:To:From; b=KujDDxo7cqn/wfQ4p7NCbSsKKCBDqCiWJG0riY5+eZ/9SKUbzYZyRHbrrxLGLXxKD 1vC2nQ7jHyFdxMTJQaz+4BnnD6WVTnGTO6GgUgPkjvBhnEAN+iF/UkI47utGSChMEe 0kILekARpGHXfIBdtgyOjJurvA7wveusv8q/uvifro9fqZtGi2rrXlQCUbvMDSj4cN et9/CckyT/CfaAeV4UYWNXA6sVknZLB8/Hap4cQhgdT8+S0VU4VhmFtpA5oefBssr5 j9o1sVSBs4nhbhJMgh7PK6WzHb1MnDiFYnzJIrIuB9mNFJQ5K4zkndF1hCkC41KedX V7hFPcRfb6c0A== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id JMfR9GGLQiBw; Wed, 25 Jun 2025 10:14:52 -0700 (PDT) Received: from penguin.cs.ucla.edu (unknown [47.154.30.222]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id C7D093C00D409; Wed, 25 Jun 2025 10:14:52 -0700 (PDT) Message-ID: <9d801964-8b49-4bb2-9ae7-a6419dd0ba06@cs.ucla.edu> Date: Wed, 25 Jun 2025 10:14:52 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird References: <8734bphue3.fsf@hobgoblin.ariadne.com> Content-Language: en-US From: Paul Eggert Organization: UCLA Computer Science Department In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) 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.0 (-) On 2025-06-24 22:28, Thomas G=C3=BCttler Mailinglisten wrote: > During the last months I wrote > a lot of Bash code, and often I needed to handle the non-zero exit code= of > grep. >=20 > It would be handy to have an option to make grep always return zero (ex= cept > "file not found" or similar errors). I dunno, there are several commands like grep that return exit status=20 1/2 for different kinds of "failure". ("diff", for example.) I doubt=20 whether we want to add such an option to all these commands. "grep GREPARGS || test $? =3D 1" is short and easy to remember and has=20 worked everywhere for decades. If you dislike its syntax you can package=20 it inside a shell function. From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 Resent-From: Dennis Clarke Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Wed, 25 Jun 2025 17:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 78891@debbugs.gnu.org X-Debbugs-Original-To: bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.175087389726580 (code B ref -1); Wed, 25 Jun 2025 17:52:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 Jun 2025 17:51:37 +0000 Received: from localhost ([127.0.0.1]:38917 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uUUHY-0006ub-Ma for submit@debbugs.gnu.org; Wed, 25 Jun 2025 13:51:37 -0400 Received: from lists.gnu.org ([2001:470:142::17]:50052) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uUUHV-0006tW-UM for submit@debbugs.gnu.org; Wed, 25 Jun 2025 13:51:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uUUHO-0006xV-G2 for bug-grep@gnu.org; Wed, 25 Jun 2025 13:51:26 -0400 Received: from mail.oetec.com ([108.160.241.186]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uUUHL-0008I7-J4 for bug-grep@gnu.org; Wed, 25 Jun 2025 13:51:26 -0400 Received: from [172.16.35.3] (pool-99-253-118-250.cpe.net.cable.rogers.com [99.253.118.250]) (authenticated bits=0) by mail.oetec.com (8.17.1/8.17.1) with ESMTPSA id 55PHpFrd048135 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 25 Jun 2025 13:51:16 -0400 (EDT) (envelope-from dclarke@blastwave.org) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=blastwave.org; s=default; t=1750873876; bh=IYclyyGfWF5a1kFEaqxrfy9PwJPsY8zQDCNWt3xnv7g=; h=Date:Subject:To:References:From:In-Reply-To; b=KnEH5EpNaL3kWUm9SDY2Ful0V/s6coA1rSimr4lHsYZSwo+JLvvldbIyOwuDJJXlT Q2Im3W3xGeUf4XqqP8UTtx9j1AHaURfjfsOlCYYicXvr8YnnMz5KiyACIK12eGxiQj 86rk8bVsplDNfrYV59iRYIIsgHykktjiPX8PVZHKPbF+S8FXQnczjoViNHyistF7U/ CFvaILvKptKP2/8gaJ7fqqrS8oX5fJ7pBmhJu0H7JAdJzfEFLNXMrMx2qQJB9bStwk NjK3degMubQdJVQ8/ciFjxd5v0zkkZ5AUPEpR1I+vFDeaDWemnodXT+baIo/kJ7L99 wRkArROb7fLGg== Message-ID: <4c87033c-a4b3-4f37-b817-720f44114cc2@blastwave.org> Date: Wed, 25 Jun 2025 13:51:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-CA References: <8734bphue3.fsf@hobgoblin.ariadne.com> <9d801964-8b49-4bb2-9ae7-a6419dd0ba06@cs.ucla.edu> From: Dennis Clarke Organization: GENUNIX In-Reply-To: <9d801964-8b49-4bb2-9ae7-a6419dd0ba06@cs.ucla.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-oetec-MailScanner-Information: Please contact the ISP for more information X-oetec-MailScanner-ID: 55PHpFrd048135 X-oetec-MailScanner: Found to be clean X-oetec-MailScanner-From: dclarke@blastwave.org X-Spam-Status: No Received-SPF: pass client-ip=108.160.241.186; envelope-from=dclarke@blastwave.org; helo=mail.oetec.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.0 (/) 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.0 (-) On 6/25/25 13:14, Paul Eggert wrote: > On 2025-06-24 22:28, Thomas Güttler Mailinglisten wrote: >>   During the last months I wrote >> a lot of Bash code, and often I needed to handle the non-zero exit >> code of >> grep. >> >> It would be handy to have an option to make grep always return zero >> (except >> "file not found" or similar errors). > > I dunno, there are several commands like grep that return exit status > 1/2 for different kinds of "failure". ("diff", for example.) I doubt > whether we want to add such an option to all these commands. > > "grep GREPARGS || test $? = 1" is short and easy to remember and has > worked everywhere for decades. If you dislike its syntax you can package > it inside a shell function. > > I am at great risk of falling into a bike shed[1] here. If grep works fine and all is happy then we get a zero return value. All other possible situations *should* return a non-zero error status that helps silly old UNIX people like me. If someone needs to write if-then-else-what? clause stuff in code then that is correct behavior. Why fix that which works fine? -- -- Dennis Clarke RISC-V/SPARC/PPC/ARM/CISC UNIX and Linux spoken [1] https://en.wikipedia.org/wiki/Law_of_triviality From unknown Fri Aug 15 18:06:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78891: Option to make grep always exit with 0 References: Resent-From: "Dale R. Worley" Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 26 Jun 2025 00:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78891 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Thomas =?UTF-8?Q?G=C3=BCttler?= Mailinglisten Cc: 78891@debbugs.gnu.org Received: via spool by 78891-submit@debbugs.gnu.org id=B78891.17508990037770 (code B ref 78891); Thu, 26 Jun 2025 00:51:01 +0000 Received: (at 78891) by debbugs.gnu.org; 26 Jun 2025 00:50:03 +0000 Received: from localhost ([127.0.0.1]:41788 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uUaoU-00021E-53 for submit@debbugs.gnu.org; Wed, 25 Jun 2025 20:50:02 -0400 Received: from resdmta-c2p-566138.sys.comcast.net ([2001:558:fd00:56::e]:41846) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uUaoR-00020F-VT for 78891@debbugs.gnu.org; Wed, 25 Jun 2025 20:50:00 -0400 Received: from resomta-c2p-555482.sys.comcast.net ([96.102.18.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 256/256 bits) (Client did not present a certificate) by resdmta-c2p-566138.sys.comcast.net with ESMTPS id UQjBulDSGlXqnUaoLupSwW; Thu, 26 Jun 2025 00:49:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1750898993; bh=dJguycZfFcsQuEeQ+3ClVBkU2fJBTz8lVkInEjMtGv8=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Xfinity-Spam-Result; b=cI5pW4rAK8dGiJkxmZzIIIXU1dVm7k+X31suwX+YpVfq0vnd9y/rdbX2qTescHKfv ObMB+/yIA3hHb3nhZdZF9t2C47S1aD5mHrQUs+I+qxewtvlLZT60EUd6StwpD0sBfY 8ZzobrNs8ETSG156YYiB80nUAhRoc+gQMc3Ycm2ZK/ufeyGigPHfiEYl8QnGiny1Iq 0cQjNPUN5zq7XMi5ZTlQqld5Pbnnv8E5COenyxmNx3YVjFkQJBWj0o/R48MUazxIey 3LS4OujnMeVPqe7/O0jGC2s1WOYRHP7h5hsBmEIAQHwHTMcY4EqxVnyLzuJ0V+4ECO QA640S+GYqBvg== Received: from hobgoblin.ariadne.com ([IPv6:2601:192:4a00:430::db]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 256/256 bits) (Client did not present a certificate) by resomta-c2p-555482.sys.comcast.net with ESMTPSA id UaoIuBirGgKUWUaoJuI2en; Thu, 26 Jun 2025 00:49:53 +0000 Received: from hobgoblin.ariadne.com (localhost [127.0.0.1]) by hobgoblin.ariadne.com (8.16.1/8.16.1) with ESMTPS id 55Q0noWi3173237 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 25 Jun 2025 20:49:50 -0400 Received: (from worley@localhost) by hobgoblin.ariadne.com (8.16.1/8.16.1/Submit) id 55Q0nnsx3173234; Wed, 25 Jun 2025 20:49:49 -0400 X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to Dale.Worley@comcast.net using -f From: "Dale R. Worley" In-Reply-To: (guettliml@gmail.com) Date: Wed, 25 Jun 2025 20:49:49 -0400 Message-ID: <8734bne382.fsf@hobgoblin.ariadne.com> X-CMAE-Envelope: MS4xfGUtUR+ZmaxMqn1xa7l8hDNnvDXAtPS/i2/6tvd6AN8dLGJhHH44cVv0fEN0q93rT3ZkNLiKRq6eM+IHZ+EkTBzQZfSRR/eUXIR09iJiqGL4qi4oVkH5 CBv7qdM0iMhg8gm0rWSSC3SV6+MNqf9Sa1fcTVPRypo1FlOn76r8pcCvuOZVPV/BrjguR6FSHjKrp67kaFpxwVLKjH23fqY9tSlAiKTutR0RX/i/vTl/dgQ8 wVdmcGYf+kxRAY2K139/5w== X-Spam-Score: 0.2 (/) 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.8 (/) Thomas Güttler Mailinglisten writes: > Hi Dale, thank you for your reply. Currently, I work around like this: > > echo -e "foo\nbar" | { grep '^#' >comments.txt || true; } | > some-other-command The difficulty with that code is that it doesn't satisfy the requirement you stated: > Afaik there is no option to make `grep` always exit with a zero exit > status. No matter if a match was found or not. Errors like "file not found" > should still return a non-zero exit status. That's why you need the test "$? != 2". Dale