LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-14-2006, 12:48 AM   #1
vishalbutte
Member
 
Registered: Dec 2005
Posts: 80

Rep: Reputation: 15
Question relative to absolute path


how to get the absolute path from relative path in shell script? is there any other command and function than pwd.?


thanks in advance
 
Old 01-14-2006, 01:20 AM   #2
paragn
Member
 
Registered: Jan 2006
Distribution: Red Hat EL5, Fedora 7
Posts: 259

Rep: Reputation: 30
hi,
I dont think its possible to get absolute path from relative path as the same name of file may exist to any other location so you will get all those entries of given relative path of filename.
 
Old 01-14-2006, 04:39 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by paragn
I dont think its possible to get absolute path from relative path as the same name of file may exist to any other location so you will get all those entries of given relative path of filename.
No. It is possible. A relative path is relative to the current working directory. So there is only one full path for a relative path.

Debian comes with a shell utility called "realpath", but it's not installed by default, and not all distributions provide it. The program "realpath" also resolves "..", "." and symbolic links to get the one-and-only full path.

If you really need to, such program is quite easy to make, because there is a "realpath()" C-function in the standard C-library. See "man 3 realpath".
 
Old 01-14-2006, 05:28 AM   #4
paragn
Member
 
Registered: Jan 2006
Distribution: Red Hat EL5, Fedora 7
Posts: 259

Rep: Reputation: 30
hi Hko,
oh i was not knowing this thing. Thanks for the info
 
Old 01-14-2006, 03:17 PM   #5
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
try this,
Code:
p="../../dirname/filename.bin"
wdsave="`pwd`"
cd "`dirname "$p"`"
absolutepath="`pwd`/`basename $p`"
cd "$wdsave"
 
  


Reply


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
Absolute and relative paths Gins Linux - General 6 11-08-2008 08:48 PM
Image Path reference in Linux (Absolute path) javabuddy Linux - General 7 06-05-2006 07:45 AM
how to find a relative path to another directory bahadur Programming 9 04-04-2005 07:52 PM
relative/absolute paths in Java djgerbavore Programming 2 10-26-2004 08:01 PM
Relative Path? mikeshn Linux - General 3 05-10-2002 04:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:51 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration