LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 05-28-2009, 08:07 AM   #1
maggus
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?


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
 
Old 05-28-2009, 08:26 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 286

Rep: Reputation: 61
Have a look here http://stackoverflow.com/questions/7...a-shell-script
 
Old 05-28-2009, 08:27 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,141

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

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


Reply

Tags
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 10:25 AM
Invoking a PHP script - sometimes the full path is required sneakyimp Linux - Newbie 4 05-26-2008 05:38 PM
how to use script sed with full path azeus Programming 8 03-14-2008 05:23 AM
Run any Script without metioning the full path shipon_97 Linux - Newbie 2 08-08-2006 10:49 PM
export $PATH inside script gmitra Programming 3 02-01-2005 08:34 AM


All times are GMT -5. The time now is 01:04 PM.

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