Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Tue, 11 May 2004 21:49:44 -0400 (EDT) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Song Ken Vern-E11804 cc: cygwin AT cygwin DOT com Subject: Re: Behaviour of 'find' under 'bash' In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: X-Scanned-By: MIMEDefang 2.39 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 AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT 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/