This is the mail archive of the cygwin@sourceware.cygnus.com 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]

My own which/whence


I found myself without which a while back and rolled my own.  It also will
search for non-executable files and on other 'path' variables.

==================
:
# onn_path.sh: Echo full specification of a file found in a search list
#   Normally called in back-quotes
#   _Don't_ execute with . !!!
# -q      = Quiet, don't complain if not found
# -m      = Multiple, report all files found on path
# '$1'    = File name
# '$2'... = Search list and additional directories to search

Once=true
Noisy=true
while [ $# -gt 0 ]; do
   case X$1 in
      X-m) Once=false; shift ;;
      X-q) Noisy=false; shift ;;
        *) break ;;
   esac
done
if [ $# -lt 2 ]; then exit 1; fi

# Get the file name and parse search list
file=$1; shift
list=`echo $* | \
      sed -e 's/^:/\.:/g' -e 's/::/:\.:/g' -e 's/:$/:\./g' -e 's/:/ /g'`

# Seek out the file
None=true
if [ `basename $file` != "$file" ]; then
   if [ -r $file ]; then echo $file; None=false; $Once && exit 0; fi
else
   for dir in $list; do
      if [ -r $dir/$file ]; then
         echo $dir/$file; None=false; $Once && exit 0
      fi
   done
fi
if $Noisy && $None; then
    echo no $file in $list >&2
fi

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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