#! /bin/bash

#
# Name          : $HOME/bin/which.bash or /cygnus/cygwin-b20/bin/which
#
# Version       : 1.1
#
# Author        : Gerard van Wageningen
#
# Description   : Program to show which program you get when typing it from
# 		  command line. Adapted from the which program on a HP box
#		  which was an implementation for the csh-shell (Korn-shell
#		  uses whence).
#
# 1.0   First Version
# 1.1   Changed header
#

for arg in $*
do
#  alius=`alias $arg 2>&1`
  alius=`grep "alias ${arg}=" $HOME/.bashrc`
  case $?
  in
    0)
      echo "${arg}:	aliased to `echo $alius | awk -F= '{print $2}'`"
      continue
      ;;
    *)
      ;;
  esac
  found=""
  if [ `basename $arg` != "$arg" ]
  then
    if [ -e $arg ]
    then
      echo "${arg}:	$PWD/$arg"
    else
      echo "$arg not found"
    fi
    continue
  else
    path=${path:-`echo $PATH | tr -s ':' ' '`}
    for i in $path
    do
      if [ -x $i/$arg ] && [ ! -d $i/$arg ]
      then
        echo "${arg}:	$i/$arg"
        found="Yes"
        break
      fi
    done
  fi
  if [ "$found" != "Yes" ]
  then
#    echo "No $arg in $path"
    echo "${arg}:	not found"
  fi
done

############# EOF ############
