HP3000-L Archives

October 2001, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mark Bixby <[log in to unmask]>
Reply To:
Mark Bixby <[log in to unmask]>
Date:
Mon, 22 Oct 2001 19:43:43 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (56 lines)
Ooooh, this was a good one!  :-)

john wrote:
>
> Hello,
> I need help with the find command for a korn shell script I am
> writting for the HP-UX rel 10.20. When I attempt to use a variable in
> the following statements I get hits for files that I wanted to be
> excluded. If I replace the contents of the variable directly into the
> statement, then the output is OK. It appear to me that when a variable
> is used the single qoute (') around *.fail are being interprited wrong
> (yes, the  must be there or it will not work if there are more that
> one file of that type). I realize this seems trivial but this is just
> an example. The real variable I intend to use has about 35 different
> file types that I am trying to exclude and is used in multiple places.
>
> to try this out, create the following four test files containing any
> text.
> find_ok_1.fail
> find_ok_2.fail
> find_ok_1.pass
> find_ok_2.pass
>
> execute the following and the output is correct.
>
> for i in `find . \( -type f ! -name '*.fail' \)`
> do
>    echo $i
> done
>
> now, execute this and it doesn't work (it finds the "fail" files)
>
> file_exclude="-type f ! -name '*.fail'"
> for i in `find . \( $file_exclude \)`

Try this instead:

for i in `eval "find . \( $file_exclude \)"`

> do
>    echo $i
> done

What appeared to be happening in the original was that the single quotes around
the -name value were being passed to the find command instead of being stripped
by the shell.  The call to eval forces the shell to parse everything a second
time, removing the quotes.

I have no idea if this behavior is documented somewhere or is a bug.
--
[log in to unmask]
Remainder of .sig suppressed to conserve scarce California electrons...

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2