GNU bug report logs - #23227
Inconsistent behavior for --file=~/some-file

Previous Next

Package: grep;

Reported by: Santiago Ruano Rincón <santiagorr <at> riseup.net>

Date: Tue, 5 Apr 2016 21:56:01 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


Message #15 received at 23227 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: 23227 <at> debbugs.gnu.org, santiagorr <at> riseup.net
Subject: Re: bug#23227: Inconsistent behavior for --file=~/some-file
Date: Tue, 5 Apr 2016 16:14:03 -0600
[Message part 1 (text/plain, inline)]
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.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 9 years and 105 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.