[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

obtaining the absolute path of a shell script within itself

in a shell script, $0 contains the name of the script as it was
called. i.e.

how can i obtain the absolute path of the script within itself, given
this information. one possible solution is

  echo `pwd`/$0,

which returns a POSIX-valid path like

but this method only works for relative paths. if i call myscript as

then this method yields


which is a different path (and most likely invalid).

i *could* check the first character for a '/' and act accordingly, but
there's got to be an easier way...

martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
i took an iq test and the results were negative.

Reply to: