diff options
author | Clint Adams <schizo@debian.org> | 2005-06-21 23:30:25 +0000 |
---|---|---|
committer | Clint Adams <schizo@debian.org> | 2005-06-21 23:30:25 +0000 |
commit | c2a1c435ef5e7d590328802ce333de410ce40cb6 (patch) | |
tree | 6095e344242e76daf58d6d42afc5ca29673d2a0a /which | |
download | debianutils-c2a1c435ef5e7d590328802ce333de410ce40cb6.tar.gz |
tag of schizo@debian.org--2004-primary/debianutils--etch--0--version-0
(automatically generated log message)
git-archimport-id: schizo@debian.org--etch/debianutils--etch--0--base-0
Diffstat (limited to 'which')
-rw-r--r-- | which | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#! /bin/sh +set -ef + +ALLMATCHES=0 + +while getopts a whichopts +do + case "$whichopts" in + a) ALLMATCHES=1 ;; + ?) printf "Usage: %s [-a] args\n" $0 ; exit 2 ;; + esac +done +shift $(($OPTIND - 1)) + +if [ "$#" -eq 0 ]; then + ALLRET=1 +else + ALLRET=0 +fi +case $PATH in + *::) : "not *DIR:" ;; + *:) PATH="$PATH:" ;; +esac +for PROGRAM in "$@"; do + RET=1 + IFS_SAVE="$IFS" + IFS=: + case $PROGRAM in + */*) + if [ -f "$PROGRAM" ] && [ -x "$PROGRAM" ]; then + printf '%s\n' "$PROGRAM" + RET=0 + fi + ;; + *) + for ELEMENT in $PATH; do + if [ -z "$ELEMENT" ]; then + ELEMENT=. + fi + if [ -f "$ELEMENT/$PROGRAM" ] && [ -x "$ELEMENT/$PROGRAM" ]; then + printf '%s\n' "$ELEMENT/$PROGRAM" + RET=0 + [ "$ALLMATCHES" -eq 1 ] || break + fi + done + ;; + esac + IFS="$IFS_SAVE" + if [ "$RET" -ne 0 ]; then + ALLRET=1 + fi +done + +exit "$ALLRET" |