building a command string - separating commands and arguments



Hi All,

I am trying to build a set of functions to make it easier to search
through large sets of file names.

For example, I want to turn this (BASE):
find . -iname "*.java" | grep -i FirstTerm | grep -i SecondTerm

into this (TARGET):
fjg FirstTerm SecondTerm.

Where I have a generic function that will search on any file extension
it is given, and a set of extension specific helpers.

Here is my attempt so far.

# Helper for ".java" files.
fjg() {
fXXXgBase java "$@"
}

# Generic function for any file extension.
fXXXgBase() {
command='find . -iname "*.'"$1"'" '
shift
repeatPart=' | grep -i '
until [ -z "$1" ] # Until all parameters used up . . .
do
command="${command} ${repeatPart} $1"
shift
done
echo Command: ${command}
$command
}


I get the following error from running the target command:
fjg FirstTerm SecondTerm
Command: find . -iname "*.java" | grep -i FirstTerm | grep -i
SecondTerm
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

So it would seem that my the pipes are all being lumped into the first
command or something similar...

Another tack I have tried is to do the general find first, execute
successive greps against it and output the filtered result. This
works, but is substantially slower than executing my base command
directly:
find . -iname "*.java" | grep -i FirstTerm | grep -i SecondTerm

Any assistance would be most appreciated!

Rob
:)

.



Relevant Pages

  • Re: Setting echoed string to command
    ... > directory path, file extension, and a series of variables (user is ... Are you sure that's the command you want to execute? ... > many files in the target directory with the same file extension (I get ...
    (comp.unix.shell)
  • [Full-Disclosure] Advanced usage of system() function.
    ... and call its arguments as a command for shell. ... as we can see we still didnt get what we want (typing exit ... Connection closed by foreign host. ... think what we want to execute. ...
    (Full-Disclosure)
  • Advanced usage of system() function.
    ... and call its arguments as a command for shell. ... as we can see we still didnt get what we want (typing exit we are ... Connection closed by foreign host. ... think what we want to execute. ...
    (Bugtraq)
  • Re: Wait for background processes to complete
    ... To be able to execute commands in the background and wait for their ... The documentation I am referring to is http://perldoc.perl.org/. ... You can run a command in the background with: ... There is a general problem with perl documentation: ...
    (comp.lang.perl.misc)
  • Execute Process Task not failing, but not executing the batch comm
    ... I can execute the following command from the windows "Run" prompt and it ... Might I have something set weird in SQL Server? ... server being by default configured to run as localsystem account, ...
    (microsoft.public.sqlserver.dts)