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

From: Santiago Ruano Rincón <[email-masked]>
Date: Wed, 6 Apr 2016 10:10:35 +0200

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