Help Understanding While Loop
parv at pair.com
Sat Oct 15 23:33:06 PDT 2005
in message <435189CD.8080606 at mykitchentable.net>,
wrote Drew Tomlinson thusly...
> Thus I set the following variables:
> find_args="-iname '*.jpg' -or -iname '*.gif'"
> Then I called the 'find' command as follows:
> for original in $(/usr/bin/find $remote_pictures_dir $find_args -print)
> But when I run my script, I get "/usr/bin/find: invalid predicate
> `-iname '*.jpg' -or -iname '*.gif''".
I don't get the "invalid predicate"; i get nothing printed at all
(bash3 & sh).
> However if I don't try and
> use $find_args and type the arguments in specifically, the script
> runs fine.
Are you really sure about the "runs fine" part? Here, when the
"-iname" options were not surrounded by '\(' & '\)', find searched
only for the last option, in this case "-iname '*.gif'", ignoring
all the '*.jpg' files.
> I tried various combinations of quoting and escaping
> those quotes but can't come up with a combination that works.
Add "eval" before "find" so that find recognizes $find_args as
separate options not one long string, and group $find_args to make
it work what you actually wanted ...
for f in $( eval "find $dir \( $find_args \) -print" )
More information about the freebsd-questions