[Top][All Lists]

[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:03:48 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1

tag 23227 notabug

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

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]