A2osX/BIN/WHICH.txt

78 lines
1.2 KiB
Plaintext
Raw Normal View History

NEW
PREFIX
AUTO 4,1
#!/bin/sh
#
# which
#
# locates a program in path
#
set -E
if [ -z $1 ]
echo "USAGE: which program ..."
exit 120
fi
set T = "${TEMP}which$$.tmp"
set A = 0
set F = 0
set S = 0
set L = 1
# get options
while [ ${L} -eq 1 ]
if [ $1 = "-a" ] or [ $1 = "-A" ]
set A = 1
shift
else
if [ $1 = "-s" ] or [ $1 = "-S" ]
set S = 1
shift
else
set L = 0
fi
fi
loop
# split dirs in path
echo ${PATH} > ${T}
set L = `sed "s/:/ /" ${T}`
rm -q -c ${T}*
# find instances
while [ $# -gt 0 ]
set F = ${F} + 1
for D in ${L}
# check for file
if [ ${S} -eq 0 ]
ls -f ${D}$1
set T = $?
else
ls -f ${D}$1 > /dev/null
set T = $?
fi
# process result
if [ ${T} -eq 0 ]
set F = ${F} - 1
if [ ${A} -eq 0 ]
break
fi
fi
next
shift
loop
# -s numeric result
if [ ${S} -gt 0 ]
if [ ${F} -eq 0 ]
exit 0
else
exit 70
fi
MAN
TEXT /BIN/which