GNU bug report logs -
#23227
Inconsistent behavior for --file=~/some-file
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
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 23227 <at> debbugs.gnu.org.
--
23227: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23227
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
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
[signature.asc (application/pgp-signature, attachment)]
[Message part 5 (message/rfc822, inline)]
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
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.