How does a program get its path name?

Cary W. Fitzgerald cwf at cbterra.ATT.COM
Wed Mar 9 06:07:15 AEST 1988


In article <873 at hsi.UUCP> palmer at hsi.UUCP (Mike Palmer) writes:
>In article <4210002 at hpcllf.HP.COM>, jws at hpcllf.HP.COM (John Stafford) writes:
>> The name a program was invoked under is in argv[0]; that may (or more
>> likely may not) contain the "full" path name.
>
>this can be combined with the info obtained by calling the function
>	getwd(pathname)
>	char *pathname;

What if the program is on your PATH?  You'll have to simulate the shell's
behavior to get the path name.  The PATH variable must, of course, be exported,
so you'll be assured of being able to look at it.

If the command was invoked through an alias, command substituion will already
have been done, so you don't have to consider that case.


Cary.



More information about the Comp.unix.questions mailing list