How to get the pathname of the current executable?

John Chambers jc at minya.UUCP
Thu Feb 15 14:31:54 AEST 1990


> As long as you're still in the directory from which the
> program was run, and as long as your path was the same
> as the one set in your .cshrc (someone please tell me
> why which(1) reads the .cshrc...) then you'll come up
> with /usr/foo/bar/bletch/prog, barring surreptition.

I've been mystified about this on some Ultrix machines at work,
especially since this causes it to give the wrong result most
of the time.  When I got ahold of this machine (an ESIX system), 
I was further surprised to find that which didn't even exist.  
And here I'd thought it was a universal csh builtin.  Just shows 
how naive I was.

So I decided to try my hand at implementing it.  Half an hour later,
I had it working.  It works in the obvious way, using the PATH from
its environment, and gives the right result.  Something even more
surprising:  You know how the csh builtin has this several-second
delay before it answers?  Well, my little program answers with no
discernable delay.

How could they have all gotten it all so wrong?  I feel like posting
my program, but I'd feel a bit silly to do so, because it's such
a piece of trivia.  I mean, talk about a Programming 101 assignment.
At least, I think I'll take it to work, so I can find things on 
the Ultrix systems.

(Random sounds of disgust and exasperation.)

-- 
John Chambers ...!{harvard,ima,mit-eddie}!minya!jc

[Sorry, no clever saying today.]



More information about the Comp.unix.questions mailing list