- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: PATH value in a variable
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 12:03 AM
07-28-2006 12:03 AM
PATH value in a variable
Please look this simple script content:
MAIN_PATH=/usr/local/bin
SUPPLEMENTARY_PATH=../..
FULL_PATH=$MAIN_PATH/$SUPPLEMENTARY_PATH
echo $FULL_PATH
/usr/local/bin/../..
How can I obtain (on-the-fly) the real/final path info content into $FULL_PATH? In this case must be "/usr".
Please omit the possibility to move to $FULL_PATH and to obtain the value of $PWD, I need to know the real/final content before moving.
For those that have a solution, please think that it would happen in this deliberate erroneous case of variable definition:
SUPPLEMENTARY_PATH=../../../../../..
Rgds.
- Tags:
- PATH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 12:07 AM
07-28-2006 12:07 AM
Re: PATH value in a variable
FULL_PATH=$MAIN_PATH:$SUPPLEMENTARY_PATH
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 12:17 AM
07-28-2006 12:17 AM
Re: PATH value in a variable
You are wrong. The final PATH must be:
FULL_PATH=$MAIN_PATH/$SUPPLEMENTARY_PATH
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 12:19 AM
07-28-2006 12:19 AM
Re: PATH value in a variable
MAINPATH=/usr/local/bin
SUPPPATH=../..
while [ $(echo $SUPPPATH | grep -c "\.\.") -gt 0 ]; do
SUPPPATH=$(dirname $SUPPPATH)
MAINPATH=$(dirname $MAINPATH)
done
echo $MAINPATH
There's probably an elegant perl script that will do the same...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 12:54 AM
07-28-2006 12:54 AM
Re: PATH value in a variable
try with perl:
perl -e 'use Cwd 'abs_path'; print abs_path($ARGV[0]) . "\n";' PATHNAME
mfG Peter
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 01:00 AM
07-28-2006 01:00 AM
Re: PATH value in a variable
though functional, I recommend stripping some quotes:
perl -e 'use Cwd abs_path; print abs_path($ARGV[0]) . "\n";' PATHNAME
Sorry.
Additionally, here is a awk-function that did this as well, if I remember correctly:
awk 'function pathexp (name) { numdir=split(name,p,"/")
ndir_new=0
for(i=1;i<=numdir;i++) {
if(p[i]==".") continue
if(p[i]=="..") {if(ndir_new) {ndir_new--;continue}}
np[++ndir_new]=p[i]
}
if(!ndir_new) return(name)
new_name=np[1]
for(i=2;i<=ndir_new;i++) new_name=new_name"/"np[i]
return(new_name)
}
{print pathexp($1)}'
This expects your pathname at stdin.
mfG Peter
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 01:22 AM
07-28-2006 01:22 AM
Re: PATH value in a variable
you can set your FULL_PATH variable:
FULL_PATH=`cd $MAIN_PATH/;cd $SUPPLEMENTARY_PATH;pwd`
Enrico