Re: Tcl source command directory
- From: "Gerald W. Lester" <Gerald.Lester@xxxxxxx>
- Date: Thu, 30 Mar 2006 19:43:41 -0600
brianlum@xxxxxxxxx wrote:
I am trying to use the source command, but source only looks in the
directory where I am calling the script from, i.e. the current working
directory.
For example, if my script is in /usr/local/bin/ and if i call the
script with an absolute path from my home directory /home/user/, source
only looks for files in /home/user/.
How can I make source look in the same directory where the script is
located? I need to be able to use this as I put the script on multiple
machines and it is not always in the same directory.
Thank you for your help!
I presume what you are asking for is how to source something relative to the location of a script vs the current working directory.
So, if you wanted to source in the script foobar.tcl that is in the lib directory one up and over from the location of the current script (i.e. in your example it would be /usr/local/lib/foobar.tcl) then do:
set baseDir [file dirname [info script] ]
source [file join $baseDir .. lib foobar.tcl]
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.
- Follow-Ups:
- Re: Tcl source command directory
- From: Ray
- Re: Tcl source command directory
- References:
- Tcl source command directory
- From: brianlum
- Tcl source command directory
- Prev by Date: Tcl source command directory
- Next by Date: XmlRPC
- Previous by thread: Tcl source command directory
- Next by thread: Re: Tcl source command directory
- Index(es):
Relevant Pages
|