summaryrefslogtreecommitdiff
path: root/mkc_which
blob: 3d5c60e8f2f6ee7450a449d2f620a32e00f37b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

############################################################
# Copyright (c) 2009-2012 by Aleksey Cheusov
#
# See COPYRIGHT file in the distribution.
############################################################

# Portable replacement for which(1)

if test "$1" = "-x"; then
    failure=0
    shift
else
    failure=1
fi

if test $# -ne 1; then
    cat <<EOF
usage: mkc_which [-x] program
  -x -- exit status is always 0
EOF
    exit 1
fi

if echo "$1" | grep '^/' > /dev/null; then
    echo $1
    exit 0
fi
for i in `echo $PATH|tr : ' '`; do
    if test -x "$i/$1" -a -f "$i/$1"; then
	echo $i/$1
	exit 0
    fi
done

echo "Cannot find $1" >&2
exit $failure