Help Understanding While Loop

Drew Tomlinson drew at mykitchentable.net
Sun Oct 16 10:50:21 PDT 2005


On 10/15/2005 11:33 PM Parv wrote:

>in message <435189CD.8080606 at 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 thought I was but then after continuing to play around with it I 
noticed the phenomena you describe above.  That's when I added the '\(' 
as you mention.  Good catch!

>>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
>  
>

Thank you very much!!!  This works great.

Drew

-- 
Visit The Alchemist's Warehouse
Magic Tricks, DVDs, Videos, Books, & More!

http://www.alchemistswarehouse.com



More information about the freebsd-questions mailing list