- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Expand a path passed to a script
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
Discussions
Discussions
Forums
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
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
тАО01-19-2006 08:58 AM
тАО01-19-2006 08:58 AM
Re: Expand a path passed to a script
APP_PATH=/var/adm/syslog
RELATIVE=`echo $1 |grep "^\."|wc -l`
# If the arg starts with dot, then is relative
if [ $RELATIVE -gt 0 ]; then
if [ -d $APP_PATH/$1 ]; then
REALPATH=`cd $APP_PATH/$1;pwd`
else
FILEDIR=`dirname $APP_PATH/$1`
REALDIRPATH=`cd $FILEDIR;pwd`
FILENAME=`basename $APP_PATH/$1`
REALPATH=`echo "$REALDIRPATH/$FILENAME"`
fi
else
REALPATH=$1
fi
echo $REALPATH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 09:12 AM
тАО01-19-2006 09:12 AM
Re: Expand a path passed to a script
Excellent solution!
Not having much experience with compiling programs for Unix, I compiled it with no options and it works perfectly. None of the tests I've run have failed (unless the user provides a bogus entry but then there are larger problems anyway).
This has the added convenience of completely encapsulating the code in a single command for use in my scripts, keeping the complexity of the scripts themselves to a minimum.
I'm still going to upgrade my perl and check out that solution but I'm going to be using this as the permanent fix.
Thanks!
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 09:14 AM
тАО01-19-2006 09:14 AM
Re: Expand a path passed to a script
I appreciate the effort but what your suggesting is already as large as the brute force method I uploaded at the beginning of this thread.
As you can see from the previous post, Rodney posted a simple C program that will wrap it all up nicely for me.
Thanks,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 09:25 AM
тАО01-19-2006 09:25 AM
Re: Expand a path passed to a script
...and I can't resist noting that Rodney's C-code leverages the 'realpath()' function that the perl module I suggested you use does. :-;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2006 12:39 AM
тАО01-20-2006 12:39 AM
Re: Expand a path passed to a script
I was able to get the perl solution to work by pointing it to the newer version as shown here:
#!/bin/ksh
WHERE=`perl5.6.1 -le 'use Cwd qw(realpath);print realpath $ARGV[0];' $1`
echo $WHERE
Actually, I will likely use the perl solution in some cases and the compiled C solution in others.
The difference is, as provided above, the perl solution will generate an error if an invalid directory is passed, while the C solution will not.
Each solution has it's own merits depending on what exactly you're trying to accomplish and if/how you're going to handle invalid paths.
I want to thank everyone on this forum for their prompt responses and dedication to helping me find a workable solution. This has been a very enjoyable first experience.
Steve
- « Previous
- Next »