- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Finding absolute path of 'sourced' shell 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
тАО08-18-2009 01:53 AM
тАО08-18-2009 01:53 AM
Finding absolute path of 'sourced' shell script
The issue is that the path of this script is not fixed as it changes based on the directory it is checked out.
If it is sourced from a different directory the $PWD or `dirname` displayed is that of the directory which sources it and 'not' the directory of the 'sourced script'.
Can someone please suggest a solution for this ?
- Tags:
- source
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 01:57 AM
тАО08-18-2009 01:57 AM
Re: Finding absolute path of 'sourced' shell script
You could use the 'which' command prior to executing. This would tell you which, pardon the pun, sourced script you are executing.
HTH
Regards,
Berd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 02:24 AM
тАО08-18-2009 02:24 AM
Re: Finding absolute path of 'sourced' shell script
Sourced files do undergo $PATH lookup, not sure if that is helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 03:05 AM
тАО08-18-2009 03:05 AM
Re: Finding absolute path of 'sourced' shell script
why do not you consider a copy of source to known directory on your local ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 07:29 PM
тАО08-18-2009 07:29 PM
Re: Finding absolute path of 'sourced' shell script
To see why which and whereis are not useful:
which for
whereis for
whence -v for
The only correct answer is whence -v for. This is even more telling:
which type
whereis type
whence -v type
which and whereis both report that /usr/bin/type is the location of the command but your script will *not* run /usr/bin/type. Instead, it will run the alias. This is critically important for sourced scripts and other commands that a user may have aliased or have $PATH set to unsafe locations.
I will explictly set PATH and unset all aliases in my critical scripts to prevent accidents (or hacks):
export PATH=/usr/bin:/usr/sbin:/usr/contrib/bin
unalias -a
Bill Hassell, sysadmin
- Tags:
- whence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2009 12:20 AM
тАО08-19-2009 12:20 AM
Re: Finding absolute path of 'sourced' shell script
I always think of them as scummy C shell commands, not to be used for a real shell, unless you have a bad path setting.
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-19-2009 02:22 AM
тАО08-19-2009 02:22 AM
Re: Finding absolute path of 'sourced' shell script
Berd