[net.unix] Bug in find

wall@ucbvax.ARPA (Steve Wall) (10/04/84)

I've run into the following bug in find(1) in 4.2BSD. I know that there
was some talk on the USENET about 4 months ago regarding find, but
I'm not sure if this is what was being discussed. I'm pretty sure that
I'm using the command correctly, at least as far as the manual page goes.

The problem occurs when the -exec field is used with "ls -l" (I don't know
if it occurs with other programs that are execed). Here is a script of the 
problem:

===============================================
Script started on Thu Oct  4 07:47:30 1984
arpa % pwd
/ra/csr/wall/test

arpa % ls
1/          2/          in_test     typescript

arpa % ls 1
file_find

arpa % ls 2
file_find

arpa % find . -name file_find -exec ls -l {}\;
total 2
drwxr-xr-x  2 wall          512 Oct  4 06:46 1
drwxr-xr-x  2 wall          512 Oct  4 06:46 2
-rw-r--r--  1 wall            0 Oct  4 06:46 in_test
-rw-r--r--  1 wall            0 Oct  4 07:47 typescript
total 2
drwxr-xr-x  2 wall          512 Oct  4 06:46 1
drwxr-xr-x  2 wall          512 Oct  4 06:46 2
-rw-r--r--  1 wall            0 Oct  4 06:46 in_test
-rw-r--r--  1 wall            0 Oct  4 07:47 typescript

arpa % exit
script done on Thu Oct  4 07:48:26 1984

===============================================
The problem seems to be that "find" finds the two matches, but instead
of using the paths of the matches for the "ls -l", it uses the current
directory. This doesn't seem right. Is this a problem with "ls" or is
it a problem with "find"? I've also tried:

	find . -name file_find -print | ls -l

but that produces the same output. Any help is appreciated.

Steve Wall
wall@ucbarpa	(ARPANET)
..!ucbvax!wall	(UUCP)

alan@drivax.UUCP (Alan Fargusson) (10/05/84)

<<<< gulp >>>>

This is not a bug. The problem is that csh eats {}. try this:
	find . -name something -exec ls -l "{}" \;

matt@ucla-cs.UUCP (10/06/84)

#endif bug

>From: wall@ucbvax.ARPA (Steve Wall)
>
>I've run into the following bug in find(1) in 4.2BSD. I know that there
>was some talk on the USENET about 4 months ago regarding find, but
>I'm not sure if this is what was being discussed. I'm pretty sure that
>I'm using the command correctly, at least as far as the manual page goes.
>
>...
>arpa % find . -name file_find -exec ls -l {}\;
>...

The find command is being issued incorrectly.  Since you are using
Csh, the sequence {}\; is being ``expanded'' to `;', and you
are really doing an `ls -l' each time a file is found (prove this
to yourself with `echo {}\;').

Try:

	find . -name file_find -exec ls -l "{}" \;

which should work correctly.

					- Matt

-------
UUCP:	{ucbvax,ihnp4}!ucla-cs!locus.matt
ARPA:	matt@ucla-locus

jerry@oliveb.UUCP (Jerry Aguirre) (10/09/84)

No the csh does not eat {}.  Actually I was supprised that it didn't as
{a,b}c does have special meaning to the csh.  Apparently the shell
recognizes that {} cannot be expanded and so leaves it alone.  The real
problem with the posted line is that there is no space between the {}
and the \;.  That is:

	find . -name something -exec ls -l {}\;
    won't work but
	find . -name something -exec ls -l {} \;
    will. 			  Note space ^

Remember that the \; is the terminating argument for the string of
arguments beginning with -exec.  To be recognized it must be a separate
argument.

					    Jerry Aguirre
{hplabs|fortune|idi|ihnp4|ios|tolerant|allegra|tymix}!oliveb!jerry