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

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 05 Apr 2016 22:04:02 +0000

Your bug report

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

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
23227: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23227
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#23227: Inconsistent behavior for --file=~/some-file
From: Eric Blake <[email-masked]>
To: Santiago Ruano Rincón <[email-masked]>, [email-masked], "contr >> GNU bug control" <[email-masked]>
Date: Tue, 5 Apr 2016 16:03:48 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 23227 notabug
thanks

On 04/05/2016 03:55 PM, Santiago Ruano Rincón wrote:
> 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

That's not grep's fault, but the shell's.

> % echo "hola" | LANG=C grep --file ~/tmp-pattern
> hola
> % echo "hola" | LANG=C grep --file=${HOME}/tmp-pattern 
> hola

Try this to see that it is the shell:

$ echo testing --file ~/tmp-pattern
testing --file /home/eblake/tmp-pattern
$ echo testing --file=~/tmp-pattern
testing --file=~/tmp-pattern
$ echo testing --file=$HOME/tmp-pattern
testing --file=/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=~/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=value',
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.

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

Subject: Inconsistent behavior for --file=~/some-file
From: Santiago Ruano Rincón <[email-masked]>
To: bug-grep <[email-masked]>
Date: Tue, 5 Apr 2016 23:55:41 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

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