[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#23227: Inconsistent behavior for --file=~/some-file
From: |
Eric Blake |
Subject: |
bug#23227: Inconsistent behavior for --file=~/some-file |
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 |
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
Description: OpenPGP digital signature