File: which.test

package info (click to toggle)
qt-x11-free 3%3A3.3.8b-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 82,228 kB
  • ctags: 72,613
  • sloc: cpp: 456,781; ansic: 129,082; sh: 11,455; yacc: 2,947; xml: 766; makefile: 562; perl: 495; lex: 458; sql: 29; lisp: 13
file content (39 lines) | stat: -rwxr-xr-x 629 bytes parent folder | download | duplicates (19)
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
#!/bin/sh

HOME=/dev/null
export HOME

unset which

WHICH=`which which 2>/dev/null`
if echo $WHICH | grep 'shell built-in command' >/dev/null 2>&1; then
    WHICH=which
elif [ -z "$WHICH" ]; then
    if which which >/dev/null 2>&1; then
	WHICH=which
    else
	for a in /usr/ucb /usr/bin /bin /usr/local/bin; do
	    if [ -x $a/which ]; then
		WHICH=$a/which
		break;
	    fi
	done
    fi
fi

if [ -z "$WHICH" ]; then
    IFS=:
    for a in $PATH; do
	if [ -x $a/$1 ]; then
	    echo "$a/$1"
	    exit 0
	fi
    done
else
    a=`"$WHICH" "$1" 2>/dev/null`
    if [ ! -z "$a" -a -x "$a" ]; then
	echo "$a"
	exit 0
    fi
fi
exit 1