Subject: My own which/whence
From: [email-masked] ("Michael A. Chase")

1 Jul 1997 18:41:11 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Original-To: <[email-masked]>
Original-Cc: "Kang Su Gatlin" <[email-masked]>
X-MSMail-Priority: Normal
X-Priority: 3
X-Mailer: Microsoft Internet Mail 4.70.1161
Original-Sender: [email-masked]

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
"[email-masked]" with one line of text: "help".