Subject: Re: bug#23227: Inconsistent behavior for --file=~/some-file

From: Eric Blake <[email-masked]>
Date: Tue, 5 Apr 2016 16:14:03 -0600

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