Subject: | |
From: | |
Reply To: | |
Date: | Wed, 24 Oct 2001 16:01:17 -0600 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Mark Bixby <[log in to unmask]> wrote in message news:<[log in to unmask]>...
> 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.
To everyone who helped me, thank you. I decided to go with the
following (from mark bixby).
for i in `eval "find . \( $file_exclude \)"`
do
echo $I
done
Thanks again.
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|
|
|