File: mkc_which.in

package info (click to toggle)
mk-configure 0.36.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,996 kB
  • sloc: ansic: 4,974; makefile: 1,387; sh: 1,087; cpp: 177; perl: 101; yacc: 85; lex: 21
file content (45 lines) | stat: -rwxr-xr-x 772 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
#!/bin/sh

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

# Portable replacement for which(1)

failure=1
while getopts x f; do
    case "$f" in
	x)
	    failure=0;;
	*)
	    exit 2;;
    esac
done
shift `expr $OPTIND - 1`

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
    if test -x "$1"; then
	echo "$1"
	exit 0
    fi
else
    for i in `echo $PATH|tr : ' '`; do
	if test -x "$i/$1" -a -f "$i/$1"; then
	    echo "$i/$1"
	    exit 0
	fi
    done
fi

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