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, 2 Mar 2004 11:30:37 -0500 (EST) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Yaakov Selkowitz cc: cygwin AT cygwin DOT com Subject: Re: Better way to do this? (bash scripting) In-Reply-To: <40443616.3060108@users.sourceforge.net> Message-ID: References: <40443616 DOT 3060108 AT users DOT sourceforge DOT net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; FORMAT=flowed Content-ID: X-Scanned-By: MIMEDefang 2.39 On Tue, 2 Mar 2004, Yaakov Selkowitz wrote: > I hope this isn't considered too far OT, but perhaps someone will find > this useful. > > I wrote the attached scripts, which I place in /etc/profile.d/, in order > to get quicker access to the original-package and Cygwin-specific > documentation. (pkgdoc and cygdoc respectively) > > What I wanted to know is: > > 1) is there a better and/or more precise way of searching for the file? Well, every way I can think of will use 'find' at least once (maybe cache the results, like 'locate' does). > 2) is there a better and/or more precise way of verifying that there's > actually such a file to feed to less, instead of calling find twice? > > Thanks, > Yaakov a) You can supply multiple directories as starting points to GNU find, e.g., find /usr/bin /usr/include -type f -name \*cygwin\* -print b) Use the "-r" parameter to xargs, so that the program won't be invoked unless something is found, e.g., find /usr/bin /usr/include -type f -name \*cygwin\* -print0 | xargs -r0 ls -l c) Use the -path predicate rather than -name. Also, your scripts are not space-in-filename friendly -- a no-no for Cygwin -- and the "no documentation" message will be printed for every directory (which is not quite what you want). So, with the above fixed, the first set of 'for' loops in your pkgdoc.sh could become something like # ------------------- package_dirs=`echo "'${PKGDOC_PATH}'" | sed "s%:%' '%g"` readme_files=`eval "find $package_dirs -path '*$1-*/$2' -o \ -path '*$1/*/$2' -o -path '*$1/$2' -print | \ sed -e "s%^%'%" -e "s%$%'%"` if [ -n "$readme_files" ]; then echo $readme_files | xargs -r less else echo "No $2 documentation was found for the $1 package" fi STATUS=$? ;; # ------------------- HTH, 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/