Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!samsung!umich!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: alt.sources.d Subject: Re: Multiple executables in path (Was: NON-SOURCE POSTINGS CONSIDERED HARMFUL!) Message-ID: <17687:Jan2414:33:5091@kramden.acf.nyu.edu> Date: 24 Jan 91 14:33:50 GMT References: <8807@star.cs.vu.nl> <9688:Jan2313:09:4391@kramden.acf.nyu.edu> <8833@star.cs.vu.nl> Organization: IR Lines: 26 In article <8833@star.cs.vu.nl> maart@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