bin/which performance improvement

This commit is contained in:
Brian J. Bernstein 2023-02-09 13:10:22 -05:00
parent 17aee1f2a8
commit ef7403f937

View File

@ -1,6 +1,3 @@
NEW
PREFIX
AUTO 4,1
#!/bin/sh
#
# which
@ -10,8 +7,10 @@ AUTO 4,1
set -E
if [ -z $1 ]
echo "USAGE: which program ..."
if [ -z $1 ] or [ $1 = "-h" ] or [ $1 = "-H" ]
echo "Usage : which [options] program ..."
echo " -A show all found"
echo " -S no output, 0 if found, 1 if not"
exit 120
fi
@ -37,7 +36,7 @@ while [ ${L} -eq 1 ]
loop
# split dirs in path
echo ${PATH} > ${T}
echo "${PATH}:." > ${T}
set L = `sed "s/:/ /" ${T}`
rm -q -c ${T}*
@ -46,16 +45,18 @@ while [ $# -gt 0 ]
set F = ${F} + 1
for D in ${L}
# check for file
if [ ${S} -eq 0 ]
ls -f ${D}$1
set T = $?
if [ -f ${D}$1 ]
set T = 0
else
ls -f ${D}$1 > /dev/null
set T = $?
set T = 1
fi
# process result
if [ ${T} -eq 0 ]
if [ ${S} -eq 0 ]
echo "${D}$1"
fi
set F = ${F} - 1
if [ ${A} -eq 0 ]
break
@ -73,5 +74,3 @@ if [ ${S} -gt 0 ]
exit 70
fi
MAN
TEXT /BIN/which