building a command string - separating commands and arguments
- From: Robert Mark Bram <robertmarkbram@xxxxxxxxx>
- Date: 20 May 2007 20:32:58 -0700
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
:)
.
- Follow-Ups:
- Re: building a command string - separating commands and arguments
- From: Stephane CHAZELAS
- Re: building a command string - separating commands and arguments
- From: Bill Marcum
- Re: building a command string - separating commands and arguments
- Prev by Date: Re: bash set -m
- Next by Date: Top 10 posters comp.unix.shell
- Previous by thread: How can I disable bash ctrl-s ctrl-q feature?
- Next by thread: Re: building a command string - separating commands and arguments
- Index(es):
Relevant Pages
|