#!/bin/ksh # @(#) Find command on PATH #..# systems: #..# sites: tag=`basename $0` usage="Usage: ${tag} [-f][-ll|-lf] [-path] " path=$PATH typeset -i f=0 typeset -i i=-1 typeset -i j=0 while [ $# -gt 0 ]; do case "$1" in -x|-v) set "$1" ;; -vi*) ${1#-} $0; exit ;; -h) echo "$usage" echo "" echo "$tag searches the current PATH for commands" echo "" echo "The argument is used as a pattern to match for command" echo "names in each element of \$PATH. If a match is not" echo "found, it is retried as a partial match. The -f flag" echo "forces a partial match trial even if an exact match is" echo "found." echo "" echo "The '-ll' and '-lf' flags cause an 'ls -ld' and 'ls -F'" echo "listing of each match." echo "" echo "If '-path' is specified, is used instead of" echo "the real PATH. This allows 'what if' checks." echo "" echo "" exit ;; -about) echo "$tag was written by David Ledger, and adapted for use at" echo "HP in February 98." echo "dledger@ivdcs.demon.co.uk or 100024.330@compuserve.com" exit ;; -f) f=-1 ;; -ll) i=i+1; c[$i]="ls -l" ;; -lL) i=i+1; c[$i]="ls -Ll" ;; -lf) i=i+1; c[$i]="ls -F" ;; -file) i=i+1; c[$i]="file" ;; -wc) i=i+1; c[$i]="wc -c" ;; -[1-9]) l=${1#-} ;; -path*) path=${1#-path} ;; -[Oo][Pp][Tt]*) path="$OPTPATH" ;; +[Oo][Pp][Tt]*) path="$PATH:$OPTPATH" ;; *) [ ${#c[*]} -eq 0 ] && { i=0; c=echo; } [ $f -ge 0 ] && f=1 for d in `echo "$path" | tr ":" " "`; do [ -f $d/$1 ] && f=$((f \* 2)) && { j=0 while [ $j -le $i ]; do eval ${c[$j]} $d/$1 j=j+1 done } done [ $f -gt 1 ] && shift && continue for d in `echo "$path" | tr ":" " "`; do for n in `ls $d | grep ${case:-} "$1"`; do j=0 while [ $j -le $i ]; do eval ${c[$j]} $d/$n j=j+1 done done done ;; esac shift done [ "$d" ] || echo "${path-$PATH}" | tr ":" "\012" | |