[comp.os.minix] which

tholm@uvicctr.UUCP (Terrence W. Holm) (05/05/88)

EFTH Minix report #7  - May 1988 -  which(1)


This is an implementation of which(1) that we
wrote for Minix. Please consider this a public
domain program.

E. Baalbergen's test(1) program was modified
to support the "-x" option. The fix is included.

"man" pages are also included.


echo x - which
gres '^X' '' > which << '/'
X#!/bin/sh
X#                   which(1)            efth   1988-Apr-14
X
Xif test $# -ne 1; then
X  echo "Usage:  which  program"
X  exit 1
X  fi
X
Xpath="`IFS=: eval echo $PATH`"
X
Xfor dir in . $path; do
X  filename=$dir/$1
X  if test -f $filename -a -x $filename; then
X    echo $filename
X    exit 0
X    fi
X  done
X
Xecho "No $1 in . $path"
Xexit 1
/
echo x - which.1
gres '^X' '' > which.1 << '/'
XNAME
X    which(1)		- which program will I get
X
XSYNOPSIS
X    which  program
X
XDESCRIPTION
X    All of the directories in the current search path ($PATH)
X    are scanned for "program". The first occurrence is reported.
X
XSEE ALSO
X    whereis(1)
X
XBUGS
X    The current directory "." is always scanned first.
/
echo x - test.fix
gres '^X' '' > test.fix << '/'
X1a2,4
X> 
X> /* Added "-x" option        1988-Apr-17      efth      */
X> 
X14c17
X< 	unary-operator ::= "-r"|"-w"|"-f"|"-d"|"-s"|"-t"|"-z"|"-n";
X---
X> 	unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-s"|"-t"|"-z"|"-n";
X41a45
X> #define FILEX	23
X54a59
X> 	{"-x", FILEX, UNOP},
X182a188,189
X> 	case FILEX:
X> 		return access(nm, 1) == 0;
/
echo x - test.1
gres '^X' '' > test.1 << '/'
XNAME
X    test(1)		- test for a condition
X
XSYNOPSIS
X    test  expr
X
XDESCRIPTION
X    Test checks to see if files exist, are readable, etc. and returns
X    an exit status of zero if true and nonzero if false.  The legal
X    operators are:
X
X  	-r file    true if the file is readable
X  	-w file    true if the file is writable
X  	-x file    true if the file is executable
X  	-f file    true if the file is not a directory
X  	-d file    true if the file is a directory
X  	-s file    true if the file exists and has a size > 0
X  	-t fd      true if file descriptor fd (default 1) is a terminal
X  	-z s       true if the string s has zero length
X  	-n s       true if the string s has nonzero length
X  	s1 = s2    true if the strings s1 and s2 are identical
X  	s1 != s2   true if the strings s1 and s2 are different
X  	m -eq m    true if the integers m and n are numerically equal
X                   The operators -gt, -ge, -ne, -le, -lt may be used as well
X
X    These operands may be combined with -a (Boolean and), -o (Boolean or),
X    ! (negation).  The priority of -a is higher than that of -o.
X    Parentheses are permitted, but must be escaped to keep the shell from
X    trying to interpret them.
X
XEXAMPLE
X	test -r file		# see if file is readable
/
--------------------------------------------------------------------
               Edwin L. Froese
                  uw-beaver!ubc-vision!mprg!handel!froese

               Terrence W. Holm
                  uw-beaver!uvicctr!sirius!tholm

tholm@uvicctr.UUCP (Terrence W. Holm) (07/13/88)

[I have been asked to repost this.]


EFTH Minix report #7  - May 1988 -  which(1)


This is an implementation of which(1) for MINIX.
Please consider this a public domain program.

--------------------------------------------------------------------
#!/bin/sh
#                   which(1)            efth   1988-Apr-14

if test $# -ne 1; then
  echo "Usage:  which  program"
  exit 1
fi

path="`IFS=: eval echo $PATH`"

for dir in . $path; do
  filename=$dir/$1
  if test -f $filename -a -x $filename; then
    echo $filename
    exit 0
  fi
done

echo "No $1 in . $path"
exit 1
--------------------------------------------------------------------
               Edwin L. Froese
                  uw-beaver!ubc-cs!mprg!handel!froese

               Terrence W. Holm
                  uw-beaver!ubc-cs!uvicctr!sirius!tholm

jf@laura.UUCP (Jan-Hinrich Fessel) (03/11/89)

Hi out there!

This is The Ultimate Solution for those of you who always wanted
to know which program they have executed:-)

BTW, can anyone repost the first part of alltar.*, it seems it 
never reached Europe (maybe it was larger than 100k?).
If it is larger than 100k, please split it in order to cross the atlantic


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive".
# Contents:  which 
# Wrapped by jf@unido
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f which -a "${1}" != "-c" ; then
  echo shar: Will not over-write existing file \"which\"
else
  echo shar: Extracting \"which\"
  sed '/^X/s///' > which << '/_SHAR_EOF_'
X: List all system directories containing the argument
X: Author: Jan-Hinrich Fessel
Xif test $# -ne 1; then
X  echo "Usage:  which  name"
X  exit 1
Xfi
X
Xecho
Xecho -n $1 :' '
Xpath="`echo $PATH | tr 'A-Za-z/:' 'A-Za-z/ '`"
X
Xfor dir in $path; do
X  for file in $dir/$1 $dir/$1.*; do
X    if test -f $file; then
X      echo $file 
X      echo
X      exit 0
X    fi
X  done
Xdone
Xecho No $1 in $path
Xecho
Xexit 1
X
X
/_SHAR_EOF_

fi
# End of overwriting check

echo shar: end of shell archive
exit 0

			      Jan-Hinrich Fessel
	Universitaet Dortmund, IRB	jf@unido.uucp  ||  jf@unido.bitnet
	There's no way to delay that trouble comin' every day... F.Z.
 =============================================================================