This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Behaviour of 'find' under 'bash'


On Wed, 12 May 2004, Song Ken Vern-E11804 wrote:

> Hi,
>
> The find command seems to be behaving differently depending on the
> content of the current directory.
> [snip]
>
> When I issue a :-
>
> find ./ -name *.java
>
> It does not seem to go into the subdirectories.
>
> But when I issue a :-
>
> find ./ -name \*.java
>
> It seems like the the shell is substituting '*' with the filename in the
> current directory.

This is by design.  The shell is expanding globs (and passing them to
"find").  If you wish it to not expand the globs, you should quote them,
like you did above, or by using single or double quotes around the name,
e.g.

find . -name '*.java'
find . -name "*.java"

In your above example, find was actually told to look for files named
'XMLParser-rik.java'.  In fact, you were lucky that there was only one
.java file in your directory.  If you had more than one, find would have
punted with "paths must precede expression".

> However, when the current directory does not have a file that matches
> the pattern, then find seem to recursively search the subdirectory.

This is a feature of the shell -- if no files match a glob, the glob is
passed through unchanged (bash does this by default, although you can turn
this behavior off, so that it'll return an empty string on no matches).

> find ./ -name *.txt
> [snip list of found files]

> Is this supposed to be the correct behaviour?

As said above, this is by design.

> Because I have another cygwin installation in WinXP which shows a
> different behaviour. The shell does not substitute the filename when
> using 'find ./ -name *.txt'

Hmm, in your above example, 'find ./ -name *.txt' worked on the problem
machine as well...  Besides, if you don't quote globs, you're likely to
get all kinds of errors.  A good way to check exactly what you'll run is
to insert an 'echo' in front of the command.  As long as the command
doesn't have any redirections, you should see the exact glob expansions in
the output.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]