LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to get full path to script file inside script itself? And in case of sym links? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-full-path-to-script-file-inside-script-itself-and-in-case-of-sym-links-729080/)

maggus 05-28-2009 09:07 AM

How to get full path to script file inside script itself? And in case of sym links?
 
Hi,

When I need to get path to the script file inside script itself I use something like this:
Code:

`dirname $0`
that works file until I call the script through sym link to it. In that case above code prints the location of the link instead the original file.

Is there a way to get the path of the original script file, not the link?

Thanks,
Mike

fpmurphy 05-28-2009 09:26 AM

Have a look here http://stackoverflow.com/questions/7...a-shell-script

Guttorm 05-28-2009 09:27 AM

Hi

There is a command "realpath" that will change it to the absolute filename. But it might not be available. On Ubuntu you need to "apt-get install realpath". I don't know about Fedora.

You could try:
`realpath dirname $0`

maggus 05-28-2009 09:40 AM

Thanks, fpmurphy.
That helped.


All times are GMT -5. The time now is 01:30 AM.