Unix Shell - find problems "invalid predicate"

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2005 > find problems "invalid predicate"





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author find problems "invalid predicate"
Jim

2005-03-26, 6:05 pm

Can someone please maybe spot why the following script fails on the 2nd
invocation of find?
I simplified it somewhat to narrow down where the problem is. I actually
want to use the 2nd variation as I build the "exclude" list from a file.
I don't see the problem.

Thanks for any help.

Jim

===========
#!/bin/ksh
set -x
find . -type f -maxdepth 1 -not \( -name hello \)
exclude="-name hello"
find . -type f -maxdepth 1 -not \(" $exclude "\)
===========

Here are the results:
+ find . -type f -maxdepth 1 -not ( -name hello )
../xqnet.o
../setp
...... more files
+ exclude=-name hello
+ find . -type f -maxdepth 1 -not ( -name hello )
find: invalid predicate `( -name hello )'




Ed Morton

2005-03-26, 6:05 pm



Jim wrote:
> Can someone please maybe spot why the following script fails on the 2nd
> invocation of find?
> I simplified it somewhat to narrow down where the problem is. I actually
> want to use the 2nd variation as I build the "exclude" list from a file.
> I don't see the problem.
>
> Thanks for any help.
>
> Jim
>
> ===========
> #!/bin/ksh
> set -x
> find . -type f -maxdepth 1 -not \( -name hello \)
> exclude="-name hello"
> find . -type f -maxdepth 1 -not \(" $exclude "\)


Try it without the quotes:

find . -type f -maxdepth 1 -not \( $exclude \)

Ed.
Jim

2005-03-26, 6:05 pm

I'll be darned. Sometimes it just takes another pair of eyes. I was trying
to guarantee that there would be spaces on each side of the "nots".

Thanks,


"Ed Morton" <morton@lsupcaemnt.com> wrote in message
news:3PednUa2z_tjTdjfRVn-gg@comcast.com...
>
>
> Jim wrote:
actually[vbcol=seagreen]
>
> Try it without the quotes:
>
> find . -type f -maxdepth 1 -not \( $exclude \)
>
> Ed.



Bill Marcum

2005-03-27, 2:47 am

On Sat, 26 Mar 2005 16:36:34 -0500, Jim
<j1mw_no_spam_plz@bellsouth.net> wrote:
> I'll be darned. Sometimes it just takes another pair of eyes. I was trying
> to guarantee that there would be spaces on each side of the "nots".
>

By putting the spaces inside quotes, you cause the shell to not see them
as separators, so \(" $exclude "\) is seen as one argument instead of
three.

>
>



--
"Irrationality is the square root of all evil"
-- Douglas Hofstadter
Jim

2005-03-30, 7:55 am

I'll be darned. Sometimes it just takes another pair of eyes. I was trying
to guarantee that there would be spaces on each side of the "nots".

Thanks,


"Ed Morton" <morton@lsupcaemnt.com> wrote in message
news:3PednUa2z_tjTdjfRVn-gg@comcast.com...
>
>
> Jim wrote:
actually[vbcol=seagreen]
>
> Try it without the quotes:
>
> find . -type f -maxdepth 1 -not \( $exclude \)
>
> Ed.



Bill Marcum

2005-03-30, 7:55 am

On Sat, 26 Mar 2005 16:36:34 -0500, Jim
<j1mw_no_spam_plz@bellsouth.net> wrote:
> I'll be darned. Sometimes it just takes another pair of eyes. I was trying
> to guarantee that there would be spaces on each side of the "nots".
>

By putting the spaces inside quotes, you cause the shell to not see them
as separators, so \(" $exclude "\) is seen as one argument instead of
three.

>
>



--
"Irrationality is the square root of all evil"
-- Douglas Hofstadter
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com