Re: Finding absolute path of a script from within
Jeenu wrote:
> Hi,
>
> I'm wondering what would be the best way to get the absolute path of
> script, within it. 'basename', 'dirname' and 'pwd' don't always give
> the same output, since it depends on where you execute the script
> from. Any thoughts?
basename and dirname are simple text processing tools, which know nothing
about the filesystem. pwd, on the other hand, usually prints correct
information.
However, it's not clear whether you want to know the absolute path the
script is using as its current working dir, or the absolute path where the
script text file is located.
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
|