Path: utzoo!utgpu!cs.utexas.edu!uunet!munnari.oz.au!metro!cluster!softway!peterc From: peterc@softway.sw.oz.au (Peter Chubb) Newsgroups: alt.sources.d Subject: which() (was Re: Multiple executables in path) Message-ID: <4545@softway.sw.oz.au> Date: 31 Jan 91 04:09:28 GMT References: <17687:Jan2414:33:5091@kramden.acf.nyu.edu> Organization: Softway Pty Ltd, Sydney, Australia Lines: 33 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 For shells with echo and test built in (most of them, now!), this involves no external executables. By omitting the exit statements, all executables with the given name(s) in the path are printed out. Of course, it's trivial to convert this into a shell function, but if you do, make sure IFS is put back the way it's supposed to be! Share and enjoy! Regards, - Peter Chubb Softway Pty Ltd, P.O. Box 305, Strawberry Hills, NSW 2012, AUSTRALIA Phone: +61 2 698 2322; Fax: +61 2 699 9174; Telex: AA27987 Internet: peterc@softway.oz.au UUCP: ...!uunet!softway.oz!peterc