- 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:16 AM
тАО01-19-2006 08:16 AM
Re: Expand a path passed to a script
Leif - Thanks for the input but dirname and basename do not expand relative paths. They were one of my first attempts.
James - I appricate the quick response. I'll look into updating my perl and let you know how it turns out.
Thanks to all,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:17 AM
тАО01-19-2006 08:17 AM
Re: Expand a path passed to a script
APP_PATH=/database/app
FULLPATH=`cd $APP_PATH/$1; pwd`
echo $FULLPATH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:20 AM
тАО01-19-2006 08:20 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 a relative path, else just use the specified path
if [ $RELATIVE -gt 1 ]; then
REALPATH=`cd $APP_PATH/$1;pwd`
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:21 AM
тАО01-19-2006 08:21 AM
Re: Expand a path passed to a script
The perl update is quick and simple and so, so worthwhile. Perl 5.8.x has incorporated lots of good things into its core.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:22 AM
тАО01-19-2006 08:22 AM
Re: Expand a path passed to a script
Your solution works if the user passes a directory, and is very similar to the method I uploaded. However if they are passing a filename, it gets an error.
I need a solution for both possibilities.
Thanks for the continued effort.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:29 AM
тАО01-19-2006 08:29 AM
Re: Expand a path passed to a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:31 AM
тАО01-19-2006 08:31 AM
Re: Expand a path passed to a script
Your new solution works in most cases but not all. If you pass it a sub-directory of the current directory, it will return the current directory, instead of the full path to the sub-directory.
Your first solution did not have this problem. Also, this solution still can't handle a filename.
Thanks again,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:34 AM
тАО01-19-2006 08:34 AM
Re: Expand a path passed to a script
DIR=$(dirname ../xyz/abc.txt)
FILE=$(basename ../xyz/abc.txt)
cd $DIR
ABSOLUTE=$(pwd)
FULL_PATH=${ABSOLUTE}/${FILE}
it should work also with an absolute path or a filename only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:36 AM
тАО01-19-2006 08:36 AM
Solution#include
main(argc,argv,envp)
int argc;
char *argv[],*envp[];
{
char realp[255];
(void)realpath(argv[1],realp);
printf("%s\n",realp);
exit(0);
}
HTH
-- Rod Hills
- Tags:
- realpath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2006 08:45 AM
тАО01-19-2006 08:45 AM
Re: Expand a path passed to a script
Very close! However, if the user passes a path or filename that is already in absolute format (i.e. /home), your solution doubles the initial forward slash (i.e. //home). If they pass the root directory, it returns three forward slashes (i.e. ///).
Thanks for the effort,
Steve