Path Program

michael.p.lindner mpl at cbnewsl.ATT.COM
Fri Jun 16 23:27:53 AEST 1989


In article <702 at censor.UUCP>, markk at censor.UUCP (Mark Keating) writes:
>    After trying to work on another system I was slightly dissapointed
> to find that there was no 'path' program to be found anywhere.
> So I wrote one  -- hope you find it useful.

I have a program which does just about the same thing.  It is written in
shell.  The difference is it takes an optional path or paths, so it can also
be used for finding things like "where is this #include file found" or
"where is this source file found (by using MAKEPATH).  Here it is.  Enjoy!

Mike Lindner
attunix!mpl

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	whf.1
#	whf.sh
# This archive created: Fri Jun 16 09:04:06 1989
export PATH; PATH=/bin:$PATH
if test -f 'whf.1'
then
	echo shar: will not over-write existing file "'whf.1'"
else
cat << \SHAR_EOF > 'whf.1'
.TH WHF 1
.SH NAME
whf \- locate a file using a path
.SH SYNOPSIS
whf file [path ...]
.SH DESCRIPTION
.I Whf
will print the location of file by searching each directory in the
given path(s).
If no path is specified, $PATH is used.
If one or more paths are given, each should be a list of
colon separated directories, and are searched left-to-right.
.PP
.SH CREDITS
This utility is functionally an extension of the
.I whf
command I had on my home machine at AT&T Bell Labs.
The source is my own invention, and is not based on anything.
SHAR_EOF
fi # end of overwriting check
if test -f 'whf.sh'
then
	echo shar: will not over-write existing file "'whf.sh'"
else
cat << \SHAR_EOF > 'whf.sh'
# whf - find a file somewhere
# by Michael Lindner
IFS=":$IFS"
case "$#" in
0)
        echo >&2 "usage: $0 file [path ... ]"
        exit 1
        ;;
1)
        file="$1"
        shift
        for d in $PATH
        do
                if [ -s $d/$file ]
                then
                        echo $d/$file
                        exit 0
                fi
        done
        ;;
*)
        file="$1"
        shift
        for d in $*
        do
                if [ -s $d/$file ]
                then
                        echo $d/$file
                        exit 0
                fi
        done
        ;;
esac
echo >&2 "$0: $file not found"
exit 1
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Alt.sources mailing list