HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Obtaining "real" directory from a symbolic link
Operating System - HP-UX
1830802
Members
4792
Online
110016
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
08-10-2005 10:47 PM
08-10-2005 10:47 PM
Obtaining "real" directory from a symbolic link
Hi,
I'm attempting to obtain the path of the script that I'm running with the script below. However,if the path obtained is only a symbolic link, then I'm unable to obtain the "real" path using my script below.
May I know how should I modify my script in order to obtain the "pointed to" or "real" absolute path from the sym-link?
#!/bin/ksh
srcDir=`dirname $0`
if [ "$srcDir" = "." ] ; then
srcDir=`pwd`
fi
e.g:
Sym-link:
/home/cs/test -> /usr/sbin/realScript.ksh
My script returns:
/home/cs/test
Could anyone help me out?
Thanks in advance.
I'm attempting to obtain the path of the script that I'm running with the script below. However,if the path obtained is only a symbolic link, then I'm unable to obtain the "real" path using my script below.
May I know how should I modify my script in order to obtain the "pointed to" or "real" absolute path from the sym-link?
#!/bin/ksh
srcDir=`dirname $0`
if [ "$srcDir" = "." ] ; then
srcDir=`pwd`
fi
e.g:
Sym-link:
/home/cs/test -> /usr/sbin/realScript.ksh
My script returns:
/home/cs/test
Could anyone help me out?
Thanks in advance.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2005 10:54 PM
08-10-2005 10:54 PM
Re: Obtaining "real" directory from a symbolic link
use:
pwd -P
for Korn shell
(http://osr600doc.sco.com/en/FD_files/nav_symlinks.html)
pwd -P
for Korn shell
(http://osr600doc.sco.com/en/FD_files/nav_symlinks.html)
I don't give a damn for a man that can only spell a word one way. (M. Twain)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2005 11:53 PM
08-10-2005 11:53 PM
Re: Obtaining "real" directory from a symbolic link
You can try with file -h also as,
#!/bin/ksh
file -h $0 | grep -q link
if [[ $? -eq 0 ]]
then
file=$(file -h $0 | awk '{ print $NF}');
srcDir=`dirname $file`
else
srcDir=`dirname $0`
if [ "$srcDir" = "." ] ; then
srcDir=`pwd`
fi
fi
echo $srcDir;
exit 0
## END ##
hth.
#!/bin/ksh
file -h $0 | grep -q link
if [[ $? -eq 0 ]]
then
file=$(file -h $0 | awk '{ print $NF}');
srcDir=`dirname $file`
else
srcDir=`dirname $0`
if [ "$srcDir" = "." ] ; then
srcDir=`pwd`
fi
fi
echo $srcDir;
exit 0
## END ##
hth.
Easy to suggest when don't know about the problem!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP