Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-28-2009, 09:07 AM   #1
LQ Newbie
Registered: Apr 2006
Distribution: Puppy, Fedora, PCLinux
Posts: 19

Rep: Reputation: 0
How to get full path to script file inside script itself? And in case of sym links?


When I need to get path to the script file inside script itself I use something like this:
`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?

Old 05-28-2009, 09:26 AM   #2
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
Have a look here
Old 05-28-2009, 09:27 AM   #3
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,356

Rep: Reputation: 379Reputation: 379Reputation: 379Reputation: 379

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`
Old 05-28-2009, 09:40 AM   #4
LQ Newbie
Registered: Apr 2006
Distribution: Puppy, Fedora, PCLinux
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks, fpmurphy.
That helped.


bash, path, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing full path name for sym links using ls command rlinuxr Linux - Software 9 08-31-2008 11:25 AM
Invoking a PHP script - sometimes the full path is required sneakyimp Linux - Newbie 4 05-26-2008 06:38 PM
how to use script sed with full path azeus Programming 8 03-14-2008 06:23 AM
Run any Script without metioning the full path shipon_97 Linux - Newbie 2 08-08-2006 11:49 PM
export $PATH inside script gmitra Programming 3 02-01-2005 09:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration