From unknown Fri Aug 15 20:47:22 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#23227 <23227@debbugs.gnu.org> To: bug#23227 <23227@debbugs.gnu.org> Subject: Status: Inconsistent behavior for --file=~/some-file Reply-To: bug#23227 <23227@debbugs.gnu.org> Date: Sat, 16 Aug 2025 03:47:22 +0000 retitle 23227 Inconsistent behavior for --file=3D~/some-file reassign 23227 grep submitter 23227 Santiago Ruano Rinc=C3=B3n severity 23227 normal tag 23227 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 05 17:56:00 2016 Received: (at submit) by debbugs.gnu.org; 5 Apr 2016 21:56:00 +0000 Received: from localhost ([127.0.0.1]:50783 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anYx6-00088m-Ir for submit@debbugs.gnu.org; Tue, 05 Apr 2016 17:56:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33133) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anYx4-00088Z-Gy for submit@debbugs.gnu.org; Tue, 05 Apr 2016 17:55:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anYwy-00074B-Fj for submit@debbugs.gnu.org; Tue, 05 Apr 2016 17:55:53 -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.5 required=5.0 tests=BAYES_05,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:44680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anYwy-000743-By for submit@debbugs.gnu.org; Tue, 05 Apr 2016 17:55:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anYwx-00041L-BW for bug-grep@gnu.org; Tue, 05 Apr 2016 17:55:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anYws-0006zh-Cf for bug-grep@gnu.org; Tue, 05 Apr 2016 17:55:51 -0400 Received: from mx1.riseup.net ([198.252.153.129]:36469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anYws-0006yj-3a for bug-grep@gnu.org; Tue, 05 Apr 2016 17:55:46 -0400 Received: from piha.riseup.net (unknown [10.0.1.163]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 1C2621A1ED1 for ; Tue, 5 Apr 2016 21:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1459893345; bh=0Kn01XEZiLAfEY/7Xgoil3hkYs2HBUgLjteYLYpchck=; h=Date:From:To:Subject:From; b=no7Sulbf3/BzagWuR9CfPAm+eB1vGewZVYF89UJ0conr+SnhUXghMlLk9SQG/qUfo ZplQwgRv4EMgu4HiAd1TGw9l8UX71SQ784DNBIpzSCzgkt38Mi9ABJ2/oc5DSr/W3D GUSnRpzHCNf8QjmFHnHtC92Cyi89kt9bHhZ9eWj4= Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: santiagorr) with ESMTPSA id 780371C008D Received: by nomada (sSMTP sendmail emulation); Tue, 05 Apr 2016 23:55:41 +0200 Date: Tue, 5 Apr 2016 23:55:41 +0200 From: Santiago Ruano =?iso-8859-1?Q?Rinc=F3n?= To: bug-grep Subject: Inconsistent behavior for --file=~/some-file Message-ID: <20160405215540.GB5865@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Virus-Scanned: clamav-milter 0.99 at mx1.riseup.net X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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.1 (----) 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: -4.1 (----) Hi, grep fails to parse the tilde (~) to represent $HOME, when it is used to give a file's path to --file=, but it works with --file % echo "a" > ~/tmp-pattern % echo "hola" | LANG=C grep --file=/home/santiago/tmp-pattern hola % echo "hola" | LANG=C grep --file /home/santiago/tmp-pattern hola % echo "hola" | LANG=C grep --file ~/tmp-pattern hola % echo "hola" | LANG=C grep --file=${HOME}/tmp-pattern hola % echo "hola" | LANG=C grep --file=~/tmp-pattern grep: ~/tmp-pattern: No such file or directory This was filed in debian: https://bugs.debian.org/504804 Cheers, Santiago From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 05 18:03:55 2016 Received: (at control) by debbugs.gnu.org; 5 Apr 2016 22:03:55 +0000 Received: from localhost ([127.0.0.1]:50797 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anZ4k-0008Ld-Rw for submit@debbugs.gnu.org; Tue, 05 Apr 2016 18:03:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39298) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anZ4j-0008LN-Ig; Tue, 05 Apr 2016 18:03:54 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3DA9C00124C; Tue, 5 Apr 2016 22:03:49 +0000 (UTC) Received: from [10.3.113.124] (ovpn-113-124.phx2.redhat.com [10.3.113.124]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u35M3nUB021607; Tue, 5 Apr 2016 18:03:49 -0400 Subject: Re: bug#23227: Inconsistent behavior for --file=~/some-file To: =?UTF-8?Q?Santiago_Ruano_Rinc=c3=b3n?= , 23227-done@debbugs.gnu.org, "contr >> GNU bug control" References: <20160405215540.GB5865@riseup.net> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <57043644.5090202@redhat.com> Date: Tue, 5 Apr 2016 16:03:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <20160405215540.GB5865@riseup.net> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2sJ1SgPSDaatQtbJTnk8md8f4Xfccul5X" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Spam-Score: -6.0 (------) 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: -6.0 (------) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --2sJ1SgPSDaatQtbJTnk8md8f4Xfccul5X Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable tag 23227 notabug thanks On 04/05/2016 03:55 PM, Santiago Ruano Rinc=C3=B3n wrote: > Hi, >=20 > grep fails to parse the tilde (~) to represent $HOME, when it is used t= o > give a file's path to --file=3D, but it works with --file That's not grep's fault, but the shell's. > % echo "hola" | LANG=3DC grep --file ~/tmp-pattern > hola > % echo "hola" | LANG=3DC grep --file=3D${HOME}/tmp-pattern=20 > hola Try this to see that it is the shell: $ echo testing --file ~/tmp-pattern testing --file /home/eblake/tmp-pattern $ echo testing --file=3D~/tmp-pattern testing --file=3D~/tmp-pattern $ echo testing --file=3D$HOME/tmp-pattern testing --file=3D/home/eblake/tmp-pattern Tilde expansion in the shell is defined by POSIX to only happen if ~ occurs as the first character of a word (or, in special cases such as "export foo=3D~/bar" where a shell builtin is consuming its operands in assignment context - but this is not one of those special cases). IN other words, for ALL other uses where you are passing '--option=3Dvalue',= tilde expansion does NOT happen in 'value'; and you are correct that using '--option value' as two separate arguments (for all long options where the argument is not optional) is the easiest way to get ~ to the front of the word and thus have tilde expansion again. Since this behavior is baked into your shell, there's nothing grep can do about it, so I'm closing this as not a bug. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --2sJ1SgPSDaatQtbJTnk8md8f4Xfccul5X Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXBDZEAAoJEKeha0olJ0Nq5rMH/0XkZfg1XIXaVTyxmG7PiScl V+DiXexDD6LEEm+xzV2I6mpfN4nWzBs8IVYnu3tfx/Vmzo05tojhypVsUAdr+L5E 4lsvwV8BYxwiZVhy8Gm4Q3o7KczYkJw8TZdVWHt7yrstJcD2vwqNRxpPn6/n204o STmQNeJ0N/JbvXrsWifKNmqT1P7V4Hikq9NIAvF7zkuGIt3gxwWUc1hB+/Nb2RAQ vvF/+R8Pdn6Ky1cWnsGqtVxl1OMAwhbEoeiyfgRwJ26pzM23ffmjeTbVvp3NCrlt zVMcmpJy4DkcXS87/RbGoRmH2CDJM/Voa9Da0vYe2P9/wKkJVHd3gg+mvBeB3JI= =rLSM -----END PGP SIGNATURE----- --2sJ1SgPSDaatQtbJTnk8md8f4Xfccul5X-- From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 05 18:14:08 2016 Received: (at 23227) by debbugs.gnu.org; 5 Apr 2016 22:14:08 +0000 Received: from localhost ([127.0.0.1]:50807 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anZEd-00009n-SC for submit@debbugs.gnu.org; Tue, 05 Apr 2016 18:14:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46377) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anZEc-00009e-48 for 23227@debbugs.gnu.org; Tue, 05 Apr 2016 18:14:06 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24F2D64365; Tue, 5 Apr 2016 22:14:04 +0000 (UTC) Received: from [10.3.113.124] (ovpn-113-124.phx2.redhat.com [10.3.113.124]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u35ME3Ku014955; Tue, 5 Apr 2016 18:14:03 -0400 Subject: Re: bug#23227: Inconsistent behavior for --file=~/some-file To: 23227@debbugs.gnu.org, santiagorr@riseup.net References: <20160405215540.GB5865@riseup.net> <57043644.5090202@redhat.com> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg X-Enigmail-Draft-Status: N1110 Organization: Red Hat, Inc. Message-ID: <570438AB.5030909@redhat.com> Date: Tue, 5 Apr 2016 16:14:03 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <57043644.5090202@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BG95WMupJ0r7vUKSsWKkxpw7K5wepSDND" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 05 Apr 2016 22:14:04 +0000 (UTC) X-Spam-Score: -6.0 (------) X-Debbugs-Envelope-To: 23227 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: -6.0 (------) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --BG95WMupJ0r7vUKSsWKkxpw7K5wepSDND Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04/05/2016 04:03 PM, Eric Blake wrote: > Tilde expansion in the shell is defined by POSIX to only happen if ~ > occurs as the first character of a word >=20 > Since this behavior is baked into your shell, there's nothing grep can > do about it, so I'm closing this as not a bug. And before you argue that "surely grep could be taught to treat "--file=3D~/..." as a request to perform tilde expansion itself, since th= e shell didn't", you'd have to patch the same problem in EVERY OTHER program that has long options, AND you'd have an ambiguity for: --file '~/...' # I want a literal tilde, not shell tilde expansion That is, grep doing tilde expansion in addition to the shell could cause places where you get improper expansion in spite of intentionally using shell quoting to avoid tilde expansion. Besides, tilde expansion in general is NOT trivial to reimplement (while ~ vs. $HOME is easy, ~username is not - don't believe me? Look at how many lines of code bash uses to implement it), and it's not worth bloating every other application to redo expansion when we can already require the shell to do it for us. You just have to learn to use the shell correctly so that expansion happens where you want it. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --BG95WMupJ0r7vUKSsWKkxpw7K5wepSDND Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXBDirAAoJEKeha0olJ0NqkWQH/3tEqTDsDJiidnRvPyuofmMT r4QNmuPyNdN6QU4m1kPVkEbjoLvjS1wu9s8y0m1IOq6Z2yCqGOySwAP9U7S+45Jh oKH2SqbyQXZTakd79ayqlKElx9IyZLIevwmf1y9Wq0wDOOONnFjY3p25VSbHL55P kHOwujq4kaI0ANsvPUygc88SSAIJ+O0uDnnXUN4jpmR05NEHUab+xK35rggoaLCj NGu3BKpMdjwmVO+fm1ts90CimduGOOqoC0WYedEYnaatLha1fa7jcaD6g62KzXvG htD29PzzIl9UvYJRoe4cgHlo/GQODsWOcrR/Q9sBZTFxcch6mZOLq58gdXwVTao= =IZBO -----END PGP SIGNATURE----- --BG95WMupJ0r7vUKSsWKkxpw7K5wepSDND-- From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 06 04:10:44 2016 Received: (at 23227) by debbugs.gnu.org; 6 Apr 2016 08:10:44 +0000 Received: from localhost ([127.0.0.1]:50948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aniXz-0007Go-G3 for submit@debbugs.gnu.org; Wed, 06 Apr 2016 04:10:43 -0400 Received: from mx1.riseup.net ([198.252.153.129]:40255) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aniXx-0007Gg-LA for 23227@debbugs.gnu.org; Wed, 06 Apr 2016 04:10:42 -0400 Received: from piha.riseup.net (unknown [10.0.1.163]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id B88381A1DD0; Wed, 6 Apr 2016 08:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1459930240; bh=2zwXFmjkew6Wk6VMpeJegyVuk5yGhh0Hnm5zgDAJcgo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oicSQyJgGYTwOdg6ng8I8WJlXjzTFgpGMPeuUwv2DQHKPcp7N3q7hlqSavAnCtdii iyI5FSnbjYZDI2XHac+k0uNFXJuPGM9P6Ym2b7mD2DjFBZ3eolNIAhbmBznak13aPR 3f2ibHTA5JJw2DozcGz95VBEWVjVRJrou3A8at2c= Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: santiagorr) with ESMTPSA id EF27A1C0221 Received: by nomada (sSMTP sendmail emulation); Wed, 06 Apr 2016 10:10:35 +0200 Date: Wed, 6 Apr 2016 10:10:35 +0200 From: Santiago Ruano =?iso-8859-1?Q?Rinc=F3n?= To: Eric Blake , 504804-done@bugs.debian.org Subject: Re: bug#23227: Inconsistent behavior for --file=~/some-file Message-ID: <20160406081035.GE5865@riseup.net> References: <20160405215540.GB5865@riseup.net> <57043644.5090202@redhat.com> <570438AB.5030909@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <570438AB.5030909@redhat.com> X-Virus-Scanned: clamav-milter 0.99 at mx1.riseup.net X-Virus-Status: Clean X-Spam-Score: -1.7 (-) X-Debbugs-Envelope-To: 23227 Cc: 23227@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: -1.7 (-) El 05/04/16 a las 16:14, Eric Blake escribió: > On 04/05/2016 04:03 PM, Eric Blake wrote: > > Tilde expansion in the shell is defined by POSIX to only happen if ~ > > occurs as the first character of a word > > > > > Since this behavior is baked into your shell, there's nothing grep can > > do about it, so I'm closing this as not a bug. > > And before you argue that "surely grep could be taught to treat > "--file=~/..." as a request to perform tilde expansion itself, since the > shell didn't", you'd have to patch the same problem in EVERY OTHER > program that has long options, AND you'd have an ambiguity for: > > --file '~/...' # I want a literal tilde, not shell tilde expansion > > That is, grep doing tilde expansion in addition to the shell could cause > places where you get improper expansion in spite of intentionally using > shell quoting to avoid tilde expansion. Besides, tilde expansion in > general is NOT trivial to reimplement (while ~ vs. $HOME is easy, > ~username is not - don't believe me? Look at how many lines of code bash > uses to implement it), and it's not worth bloating every other > application to redo expansion when we can already require the shell to > do it for us. You just have to learn to use the shell correctly so that > expansion happens where you want it. > Ok, you're right! Thanks for your answer, and I'm closing this bug in Debian. Cheers, Santiago From unknown Fri Aug 15 20:47:22 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 04 May 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