Matt Wozniski wrote:
> On Sun, Jun 7, 2009 at 10:09 PM, Tim Chase wrote:
>>> fun Pgrep(pattern, file)
>>>     grep a:pattern a:file
>>>
>>>
>>> * a:file -- no such file or directory.
>>>
>>> Exactly why is echo substituting arguments when
>>> grep is not?
>> The grep expects a filename, not a variable as the 2nd argument.  Try
>>
>>   exec 'grep a:pattern '.a:file
> 
> Doesn't that need to be
> 
>   exec 'grep ' . a:pattern . ' ' . a:file
> 
> or some such?  Probably with some shellescape()'s in there, as well...


Duh, [smacks forehead] you're right.  I narrowly focused 
resolving on the "no such file or directory" error.  However, as 
soon as that error is fixed, the result will return only hits for 
files that contain the actual text "a:pattern" instead of the 
expression contained within the a:pattern variable.  So yes, if 
one wanted to be more thorough, one would use something like 
(again, 100% untested, but at least with the elements I'd expect 
to see)

   exec 'grep /'.escape(a:pattern, 'regex_chars_to_escape').'/ 
'.escape(a:file, 'shell_chars_to_escape')

I don't remember whether :grep takes "/.../" for the pattern or 
the argument wrapped in quotes, so adjust accordingly.

-tim



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to