![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Listing files with full path | r_sethu | UNIX for Dummies Questions & Answers | 5 | 06-15-2009 02:56 AM |
| List files with full path | mr_bold | Shell Programming and Scripting | 3 | 10-07-2008 12:19 PM |
| to find the file with full path | surjyap | Shell Programming and Scripting | 5 | 01-18-2008 03:26 PM |
| Finding relative path of a file | chiru_h | Shell Programming and Scripting | 4 | 04-16-2007 08:20 PM |
| vi - replacing a relative path with absolute path in a file | Yinzer955i | UNIX for Dummies Questions & Answers | 2 | 09-07-2006 11:47 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
getting full path from relative path
given a relative path, how do i convert it into a full one. i.e. if i am in
/home/polypus and i am given foo/bar then to get a full path i can just concatinate it with pwd, but what if i am given "../mama" how do i programmatically convert: /home/polypus and ../mama into /home/mama in a way that will always work no matter what relative path is passed? my first thought is to just cd to the directory and set a variable cd $rev_path full_path=`pwd` cd $original_dir it seems there must be a unix command which does this more elegantly? thanks |
|
||||
|
This is why relative paths have problems sometimes. There isn't a good way to handle absolutely any relative path, because all relative paths have an assumption:
the current working directory is "x". You are assuming /home/polypus. Unix tools are designed to do one thing very well. It's hard to make a bulletproof tool because of the cwd assumption. Because: Obviously it may not be true. So, there is no really elegant way to deal with it. You're onto one way to deal with it. For programming, you should consider avoiding relative paths unless you want the code to work if and only if it runs from a certain directory. |
|
||||
|
thanks
thanks guys for explanations and help
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|