#!/bin/sh
#
# ident "@(#)utwhich.sh	1.1	11/01/26 Oracle"
#
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
#

Usage() {
	echo "Usage: $0 [-f fpath] object"
}

findfile=false
fpath=$PATH

while getopts f: opt; do
	case $opt in
		f)
			findfile=true
			fpath=$OPTARG
			;;
		?)
			Usage
			exit 1
			;;
	esac
done

shift `expr $OPTIND - 1`
if [ $# -ne 1 ]; then
	Usage
	exit 1
fi
		
IFS=:
for dir in $fpath; do
	if ( ( $findfile && [ -f "$dir/$1" ] ) \
		|| [ -x "$dir/$1" ] ) \
	     && [ ! -d "$dir/$1" ]; then
		echo "$dir/$1"
		exit 0
	fi
done
exit 1
