delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/03/02/11:32:19

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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 <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Yaakov Selkowitz <yselkowitz AT users DOT sourceforge DOT net>
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: <Pine.GSO.4.56.0403021050520.1337@slinky.cs.nyu.edu>
References: <40443616 DOT 3060108 AT users DOT sourceforge DOT net>
MIME-Version: 1.0
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019