[Haskell-cafe] How to get a file path to the program invoked?

Brandon Allbery allbery.b at gmail.com
Thu Dec 1 21:20:03 CET 2011


On Thu, Dec 1, 2011 at 14:26, dokondr <dokondr at gmail.com> wrote:

> On the contrary, standard shell variable $0 - contains a full path to the
> program location in the directory structure, no matter from what directory
> the program was called


If the shell found it by $PATH search, $0 will be simply the program name
with no directory and you will have to repeat the PATH search yourself.
 (And the pathological case:  the user did "PATH=something yourprog", where
"something" does not contain the directory holding "yourprog".)

There is no 100% reliable way to get the executable without using something
like /proc/self/exe (only on Linux).

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111201/c62a8d94/attachment.htm>


More information about the Haskell-Cafe mailing list