Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Oct 2005 02:33:07 -0400
From:      Parv <parv@pair.com>
To:        Drew Tomlinson <drew@mykitchentable.net>
Cc:        David Kirchner <dpk@dpk.net>, FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Help Understanding While Loop
Message-ID:  <20051016063306.GB2152@holestein.holy.cow>
In-Reply-To: <435189CD.8080606@mykitchentable.net>
References:  <435027A3.8000908@mykitchentable.net> <35c231bf0510141524u133f2d1bkeb46d60e112ee413@mail.gmail.com> <435189CD.8080606@mykitchentable.net>

next in thread | previous in thread | raw e-mail | index | archive | help
in message <435189CD.8080606@mykitchentable.net>,
wrote Drew Tomlinson thusly...
>
> Thus I set the following variables:
> 
> remote_pictures_dir="/multimedia/Pictures"
> local_pictures_dir="/tv/pictures"
> 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" )
  do
    echo "$f"
  done


  - Parv

-- 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051016063306.GB2152>