linux-console.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* encapulating a find function in a script
@ 2004-01-15  0:34 BobGian
  2004-01-15  1:00 ` Mike Castle
  2004-01-15  1:55 ` Jeffrey Holle
  0 siblings, 2 replies; 7+ messages in thread
From: BobGian @ 2004-01-15  0:34 UTC (permalink / raw)
  To: jeff.holle; +Cc: linux-console

> I'm having a problem with a simple script I'm trying to develop.
>
> Its name is fgrep and its text is:
>
>         #!/bin/bash
>         find $1 -name $2 -exec grep -H $3 '{}' ';'
>
> I want to use it like "dgrep 'directory' 'file pattern' 'match text'.
>
> It doesn't match anything because of the $2 parameter.  If I replace
> "$2" with "*.cpp", it works.
>
> Can anybody tell me what is wrong and how to fix it?

Try putting double-quotes around the parameters, like:

	 find $1 -name "$2" -exec grep -H "$3" '{}' ';'

This works for me in a similar script, at least in the csh shell.

 -Bob Giansiracusa

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: encapulating a find function in a script
@ 2004-01-16 19:53 BobGian
  2004-01-16 20:09 ` Mike Castle
  0 siblings, 1 reply; 7+ messages in thread
From: BobGian @ 2004-01-16 19:53 UTC (permalink / raw)
  To: dalgoda; +Cc: linux-console, jeff.holle

> You may also find that using xargs instead of -exec is much faster
> (fewer fork/execs).
>
> Something like:
>
> find "$1" -name "$2" -print0 | xargs -0 grep -H "$3"
>
> mrc
> --

Thanks!  Tried it - works great.  Runs two or three times as fast
and with half as many page faults.

 -Bob

^ permalink raw reply	[flat|nested] 7+ messages in thread
* encapulating a find function in a script
@ 2004-01-15  0:19 Jeffrey Holle
  0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Holle @ 2004-01-15  0:19 UTC (permalink / raw)
  To: linux-console

I'm having a problem with a simple script I'm trying to develop.

Its name is fgrep and its text is:

	#!/bin/bash
	find $1 -name $2 -exec grep -H $3 '{}' ';'

I want to use it like "dgrep 'directory' 'file pattern' 'match text'.

It doesn't match anything because of the $2 parameter.  If I replace 
"$2" with "*.cpp", it works.

Can anybody tell me what is wrong and how to fix it?



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-01-16 21:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-15  0:34 encapulating a find function in a script BobGian
2004-01-15  1:00 ` Mike Castle
2004-01-15  1:55 ` Jeffrey Holle
2004-01-16 21:09   ` Jeffrey Holle
  -- strict thread matches above, loose matches on Subject: below --
2004-01-16 19:53 BobGian
2004-01-16 20:09 ` Mike Castle
2004-01-15  0:19 Jeffrey Holle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).