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