geting the real path | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

geting the real path

Shell Programming and Scripting


Tags
basename, dirname, path

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-13-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 25 August 2014, 7:46 AM EDT
Location: various
Posts: 304
Thanks: 11
Thanked 1 Time in 1 Post
MySQL geting the real path

Hi there,
Is there any way to obtain a real path from a weird path. For example :

Code:
/foo/../bar/    ->  /bar/
/foo/.          ->  /foo/

Thanks in advance
Santiago

Last edited by chebarbudo; 02-11-2009 at 03:11 AM..
Sponsored Links
    #2  
Old 11-13-2008
demwz demwz is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 27 September 2011, 4:18 AM EDT
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
$ bash -c "cd /foo/../bar/ ; pwd"
/bar


Last edited by otheus; 11-13-2008 at 05:42 AM..
Sponsored Links
    #3  
Old 11-14-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 25 August 2014, 7:46 AM EDT
Location: various
Posts: 304
Thanks: 11
Thanked 1 Time in 1 Post
Great job ! Thank you
It looks so simple ! I would never have thought about it.
What if we want to clean the path to a file ?
    #4  
Old 11-14-2008
demwz demwz is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 27 September 2011, 4:18 AM EDT
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
truncate the file from the path with dirname and basename
# dirname /foo/../bar/file
/foo/../bar
# basename /foo/../bar/file
file

clear the path and stick it together again
Sponsored Links
    #5  
Old 11-14-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 25 August 2014, 7:46 AM EDT
Location: various
Posts: 304
Thanks: 11
Thanked 1 Time in 1 Post
Great job again thx.
I'm new in this forum. Is there any way to flag my question as "solved".
This feature helps people who search something to select only "solved" threads.
Sponsored Links
    #6  
Old 11-14-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 25 August 2014, 7:46 AM EDT
Location: various
Posts: 304
Thanks: 11
Thanked 1 Time in 1 Post
MySQL

Here is another solution that I just found:

Code:
sudo aptitude install realpath
realpath -s /home/../var/./run//motd
/var/run/motd


Last edited by chebarbudo; 02-11-2009 at 03:10 AM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Kernel Modules Not geting built rupeshkp728 UNIX for Advanced & Expert Users 1 01-28-2012 11:34 AM
Geting a value dynamically from topas jayadeava AIX 4 06-03-2011 11:26 AM
geting a value out of awk script skyineyes Shell Programming and Scripting 2 05-12-2010 10:49 AM
Getting real path to directory kandrewo UNIX for Advanced & Expert Users 7 12-18-2009 03:05 PM
geting server name(ipaddress) babu@shell Shell Programming and Scripting 1 10-24-2006 09:01 AM



All times are GMT -4. The time now is 07:01 PM.