Revision 10334,
1.4 KB
checked in by ghudson, 27 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r10333,
which included commits to RCS files with non-trunk default branches.
|
-
Property svn:executable set to
*
|
Rev | Line | |
---|
[10333] | 1 | : Use /bin/sh |
---|
| 2 | # |
---|
| 3 | # $Id: iwhich,v 1.1.1.1 1997-09-03 21:08:13 ghudson Exp $ |
---|
| 4 | # |
---|
| 5 | # Report which version of a command is in use. This version of |
---|
| 6 | # "which" doesn't handle shell aliases, but it makes up for that with |
---|
| 7 | # the "-a" (report all copies) switch and the fact that it returns a |
---|
| 8 | # nonzero shell status if the command isn't found. |
---|
| 9 | # |
---|
| 10 | USAGE='Usage: which [-a] command[s]' |
---|
| 11 | # |
---|
| 12 | # For each command, the full pathname of the version that will be |
---|
| 13 | # selected from $PATH is reported. If the -a switch is given, |
---|
| 14 | # versions in $PATH that are overridden by earlier $PATH entries will |
---|
| 15 | # also be reported. The exit status is nonzero if none of the |
---|
| 16 | # commands are found anywhere in $PATH. |
---|
| 17 | # |
---|
| 18 | # $Log: not supported by cvs2svn $ |
---|
| 19 | # Revision 1.2 1995/10/11 02:31:58 geoff |
---|
| 20 | # Work around a buggy version of Ultrix test |
---|
| 21 | # |
---|
| 22 | # Revision 1.1 1995/01/15 00:13:54 geoff |
---|
| 23 | # Initial revision |
---|
| 24 | # |
---|
| 25 | # |
---|
| 26 | opath=$PATH |
---|
| 27 | PATH=/bin:/usr/bin |
---|
| 28 | all=no |
---|
| 29 | while [ $# -gt 0 ] |
---|
| 30 | do |
---|
| 31 | case "$1" in |
---|
| 32 | -a) |
---|
| 33 | all=yes |
---|
| 34 | shift |
---|
| 35 | ;; |
---|
| 36 | -*) |
---|
| 37 | echo "$USAGE" 1>&2 |
---|
| 38 | exit 2 |
---|
| 39 | ;; |
---|
| 40 | *) |
---|
| 41 | break |
---|
| 42 | ;; |
---|
| 43 | esac |
---|
| 44 | done |
---|
| 45 | case $# in |
---|
| 46 | 0) |
---|
| 47 | echo "$USAGE" 1>&2 |
---|
| 48 | exit 2 |
---|
| 49 | ;; |
---|
| 50 | esac |
---|
| 51 | opath=`echo "$opath" | sed 's/^:/.:/ |
---|
| 52 | s/::/:.:/g |
---|
| 53 | s/:$/:./ |
---|
| 54 | s/:/ /g'` |
---|
| 55 | found=false |
---|
| 56 | for file |
---|
| 57 | do |
---|
| 58 | for i in $opath |
---|
| 59 | do |
---|
| 60 | if [ \( -x $i/$file \) -a \( ! -d $i/$file \) ] |
---|
| 61 | then |
---|
| 62 | echo $i/$file |
---|
| 63 | found=true |
---|
| 64 | case "$all" in |
---|
| 65 | no) |
---|
| 66 | break |
---|
| 67 | ;; |
---|
| 68 | esac |
---|
| 69 | fi |
---|
| 70 | done |
---|
| 71 | done |
---|
| 72 | if $found |
---|
| 73 | then |
---|
| 74 | exit 0 |
---|
| 75 | else |
---|
| 76 | exit 1 |
---|
| 77 | fi |
---|
Note: See
TracBrowser
for help on using the repository browser.