Register
It is currently Thu Sep 18, 2014 7:46 pm

how to get file absolute path


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Sep 27, 2009 8:55 pm   

Joined: Mon Aug 24, 2009 3:21 am
Posts: 3
hi,everyone

I have a scripts,for example:
/data/scripts/foo1

if I execute foo1 in /data directory,how to get the foo1 absolute path in the foo1 script when I don't know scripts directory in the other path.thanks


Top
 Profile  
 PostPosted: Wed Jun 29, 2011 10:02 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Actually, this is easier than you could think. Just use PWD and some parameter expansions.

Code:
: "${abs_path:=$0}"

if [[ $0 != /* ]]; then
    abs_path=$PWD/${0#./}
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP