How to convert a relative path into an absolute one?

How to convert a relative path into an absolute one?

Post by Alberto Lusia » Sun, 06 Nov 1994 18:32:48



I searched the FAQs for this, but I was unable to find it.
I would like to do it in the Bourne shell. A way to obtain this if to
`cd' to the relative path, do a `pwd' and then `cd' back to the
starting default dir. Any better suggestion?

Greetings,
                Alberto

 
 
 

How to convert a relative path into an absolute one?

Post by Peer Torngr » Sun, 06 Nov 1994 23:09:21



>I searched the FAQs for this, but I was unable to find it.
>I would like to do it in the Bourne shell. A way to obtain this if to
>`cd' to the relative path, do a `pwd' and then `cd' back to the
>starting default dir. Any better suggestion?
>Greetings,
>            Alberto

Why cd?

abspath=`pwd`/$relpath

This assumes you don't prepend the raltive path with ./, ../,
or something like that. It will work anyway, but it won't look all that nice.
But if you just want to USE the path, it would do fine?

Also, another trap is symbolic links. Again, the path is USABLE, but you
might get an unwanted path since pwd does not report "your" view of where
you are, but the "real" path.
--
Peer Toerngren, WM-data Konsult AB, S Kyrkogatan 4, S-652 24 Karlstad (Sweden)
Tel:   +46-(0)54/18 04 25               Fax:   +46-(0)54/15 67 85

"Proper disclaimer applies wherever applicable."

 
 
 

How to convert a relative path into an absolute one?

Post by Heiner Stev » Thu, 10 Nov 1994 03:19:26


|> I searched the FAQs for this, but I was unable to find it.
|> I would like to do it in the Bourne shell. A way to obtain this if to
|> `cd' to the relative path, do a `pwd' and then `cd' back to the
|> starting default dir. Any better suggestion?

You do not have to cd to the starting default dir if you
cd in a subshell. Example:

    AbsPath=`cd $RelPath; pwd`

Heiner

 
 
 

How to convert a relative path into an absolute one?

Post by Pierre Gaumo » Mon, 07 Nov 1994 03:37:37



>I searched the FAQs for this, but I was unable to find it.
>I would like to do it in the Bourne shell. A way to obtain this if to
>`cd' to the relative path, do a `pwd' and then `cd' back to the
>starting default dir. Any better suggestion?

rel=<relative-path-name>
abs=`(cd $rel; pwd)`

With (...), no need to cd back.

Quote:>Greetings,
>            Alberto

 
 
 

How to convert a relative path into an absolute one?

Post by Hrvoje Niks » Mon, 07 Nov 1994 21:39:11



Quote:> Also, another trap is symbolic links. Again, the path is USABLE, but you
> might get an unwanted path since pwd does not report "your" view of where
> you are, but the "real" path.

It's one of the features I like in bash.  The built-in pwd reports your
view!

Hrv
--
/*************************************************************************\
| Hrvoje Niksic |If the novel writers knew how to + Login+e-mail:         |

| Student of electrical engineering  + they would ++++++++++++++++++++++++|
| University of Zagreb, Croatia      + tell jokes instead of writing novels
\*************************************************************************/

 
 
 

1. Relative path to Absolute path

I'm looking for a C algorithm to convert relative paths to an absolute
path.

For instance, I want to resolve "/usr/bin/X11/../ls" into "/usr/bin/ls."
But I would also like to generally clean up a path as well; eg.
"/usr/bin//ls" to "/usr/bin/ls," and so on.

Years ago I saw an algorithm to do this, posted here, but I have since
lost the darn thing.

Thanks for any ideas,
RH

2. sound card problem

3. Relative path to Absolute Path

4. Multiple X servers on same display

5. Symbolic Links - Absolute Paths to Relative Paths

6. Command line editing

7. C: get absolute path to a file from relative path

8. automatic power off after shutdown

9. Add an absolute path prefix only to relative paths

10. Converting relative pathnames to absolute?

11. Wanted: Routine to convert relative pathname to absolute

12. Converting absolute symbolic links to relative?

13. tarring absolute paths for relative untar