xargs still nok?

Eric Blake ericblake@comcast.net
Thu Sep 8 15:16:00 GMT 2005


> You could either use
> 
> find . -name '*.cfm' -exec grep -i something {} /dev/null \;
> 
> which would make grep to show the filename. grep will think that it 
> searches multiple files, and will not find something in /dev/null. This 
> solution works well under Unix. With Cygwin, you may not have devices 
> available in /dev, depending on your installation.

Don't spread misinformation.  Cygwin is a Unix environment
emulation, so /dev/null ALWAYS exists (none of this junk about
"depending on your installation").

But in general, your point is accurate, and not just for single
grep invocations - if you are using the grouping features of find
or xargs to invoke grep, and want to insure that grep behaves
as though it is searching multiple files (so that it will print
filenames on the line), then add /dev/null in addition to the
list of found files, in case only one file is found or the list gets
split such that the final invocation is on just one file.  It is also
helpful with xargs when you are not using the -r option, because
then even if no files are found, xargs will still invoke grep and
grep needs a filename to search.

--
Eric Blake



--
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/



More information about the Cygwin mailing list