which() (was Re: Multiple executables in path)

Maarten Litmaath maart at cs.vu.nl
Fri Feb 1 05:42:12 AEST 1991


In article <4545 at softway.sw.oz.au>,
	peterc at softway.sw.oz.au (Peter Chubb) writes:
)My favourite solution, for the Bourne shell, at least, is:
)
)#!/bin/sh
)# which -- print full pathname of executable args.
)
)for i
)do
)    IFS=":"
)    for j in $PATH
)    do
)	test -x $j/$i && echo $j/$i
)	exit 0
)    done
)done
)exit 1

This script doesn't work at all!  You meant this:

	test -x $j/$i && {
		echo $j/$i
		exit 0
	}

Furthermore this script has the same problems as other scripts that
invoke `test', as discussed before.
--
Temporary files like /tmp/sh$$ are an abomination.



More information about the Alt.sources.d mailing list