Multiple executables in path (Was: NON-SOURCE POSTINGS CONSIDERED HARMFUL!)

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Fri Jan 25 01:33:50 AEST 1991


In article <8833 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
> I like a `which' that gives the right answer all the time, that is, the
> answer to the following question:
> 	When I type a command, say `foo', which file will be executed?

#!/bin/csh
setenv WD "`pwd`"
ls -dFL `echo "$PATH" | tr : '\012' | sed -e 's:^\.$:'"$WD": -e 's:$:/'"$1": -e 's:^:/.[.]:'`\
  | sed -e 's:/\.\./:/:g' -e 's:^'"$WD"'/:./:g' -e 's/*$//p' | head -1

If this is missing any features you want, just say what they are. On
systems without symbolic links you probably have to leave out the -L;
other than that this should be reasonably portable.

(I agree, btw, that it's worth rewriting something like this in C if the
shell script isn't efficient enough.)

> )It is a mistake to have . (or any other relative directories, if your
> )system supports them) in your path.
> Nonsense.  It's a mistake to put `.' _before_ the standard directories.
> In my PATH `.' is the very last component.

Ah, so the moment you make a typing mistake you execute anybody's
program?

---Dan



More information about the Alt.sources.d mailing list