Path: utzoo!utgpu!water!watmath!clyde!att-cb!cbterra!cwf From: cwf@cbterra.ATT.COM (Cary W. Fitzgerald) Newsgroups: comp.unix.questions Subject: Re: How does a program get its path name? Message-ID: <3845@cbterra.ATT.COM> Date: 8 Mar 88 20:07:15 GMT References: <11923@brl-adm.ARPA> <4210002@hpcllf.HP.COM> <873@hsi.UUCP> Reply-To: cwf@cbterra.UUCP (Cary W. Fitzgerald) Organization: AT&T Medical Information Systems, Columbus Lines: 18 In article <873@hsi.UUCP> palmer@hsi.UUCP (Mike Palmer) writes: >In article <4210002@hpcllf.HP.COM>, jws@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.